@cnc-tools/storm 0.14.1 → 0.15.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 (404) hide show
  1. package/dist/application.js +3 -1
  2. package/dist/bin/storm.js +18 -8
  3. package/dist/build-info.js +1 -1
  4. package/dist/chunks/chunk-4U4DZ7VG.js +40 -0
  5. package/dist/chunks/{chunk-GSC6SRTW.js → chunk-5CCP36QQ.js} +1 -1
  6. package/dist/chunks/chunk-5GBMR4HM.js +966 -0
  7. package/dist/chunks/{chunk-43MWZLJR.js → chunk-5VXBKPW6.js} +1 -1
  8. package/dist/chunks/{chunk-RA4L2ACU.js → chunk-AWBSONHB.js} +88 -34
  9. package/dist/chunks/{chunk-BRUIATTR.js → chunk-CN4EFA5J.js} +59 -12
  10. package/dist/chunks/{chunk-27P2QSIM.js → chunk-CXAT7ZKP.js} +2 -2
  11. package/dist/chunks/chunk-E4PJNZVG.js +783 -0
  12. package/dist/chunks/{chunk-T6AZIDZD.js → chunk-F6N34UWB.js} +12 -244
  13. package/dist/chunks/{chunk-ZH5R7W4A.js → chunk-KC4KDJ5K.js} +147 -26
  14. package/dist/chunks/{chunk-5ED3IDUJ.js → chunk-L36GBUBB.js} +1652 -681
  15. package/dist/chunks/{chunk-QBR5VHJ7.js → chunk-OX7X4B2L.js} +7 -2
  16. package/dist/chunks/{chunk-Z5OXOZD3.js → chunk-PN5ULTTH.js} +140 -130
  17. package/dist/chunks/chunk-QUHY6FGN.js +108 -0
  18. package/dist/chunks/chunk-QVS7HRU7.js +74 -0
  19. package/dist/chunks/{chunk-UC6DULWY.js → chunk-R7XVBZOY.js} +130 -39
  20. package/dist/chunks/{chunk-YBPTMJUM.js → chunk-RAQEXKL6.js} +1120 -465
  21. package/dist/chunks/{chunk-RKONDLPS.js → chunk-SZEURWRS.js} +446 -52
  22. package/dist/chunks/chunk-TJNFVNKR.js +246 -0
  23. package/dist/chunks/{chunk-BW2ADH7U.js → chunk-VUPZH7J2.js} +1 -1
  24. package/dist/chunks/{chunk-XPCUINWS.js → chunk-XEVHP5ZW.js} +2 -2
  25. package/dist/chunks/{chunk-5TMHYH7G.js → chunk-YV7GE6EV.js} +638 -80
  26. package/dist/chunks/{chunk-GQIL3AHY.js → chunk-ZG3WQ4UF.js} +1 -1
  27. package/dist/chunks/{live-app-FBVWUUMT.js → live-app-PI3BAN6Y.js} +37 -26
  28. package/dist/command-tree.d.ts +2 -2
  29. package/dist/command-tree.js +2 -2
  30. package/dist/commands/exec/across-sandboxes-outcomes.d.ts +364 -0
  31. package/dist/commands/exec/across-sandboxes-outcomes.js +229 -0
  32. package/dist/commands/exec/across-sandboxes-run.d.ts +180 -0
  33. package/dist/commands/exec/across-sandboxes-run.js +339 -0
  34. package/dist/commands/exec/command.d.ts +577 -75
  35. package/dist/commands/exec/command.js +165 -32
  36. package/dist/commands/exec/driver-plan.d.ts +8 -2
  37. package/dist/commands/exec/driver-plan.js +13 -3
  38. package/dist/commands/exec/exec-words.d.ts +17 -3
  39. package/dist/commands/exec/exec-words.js +27 -16
  40. package/dist/commands/exec/live-view.d.ts +3 -4
  41. package/dist/commands/exec/live-view.js +37 -28
  42. package/dist/commands/exec/metadata.js +2 -2
  43. package/dist/commands/exec/mint-failed.d.ts +4 -4
  44. package/dist/commands/exec/mint-failed.js +6 -6
  45. package/dist/commands/exec/outcomes.d.ts +530 -73
  46. package/dist/commands/exec/outcomes.js +202 -66
  47. package/dist/commands/exec/plan-only.d.ts +10 -0
  48. package/dist/commands/exec/plan-only.js +46 -0
  49. package/dist/commands/exec/plan-run.d.ts +54 -35
  50. package/dist/commands/exec/plan-run.js +81 -38
  51. package/dist/commands/exec/planned-outcome.d.ts +15 -0
  52. package/dist/commands/exec/planned-outcome.js +35 -0
  53. package/dist/commands/exec/progress.d.ts +2 -2
  54. package/dist/commands/exec/progress.js +35 -18
  55. package/dist/commands/exec/resource-refusals.d.ts +2 -2
  56. package/dist/commands/exec/resource-refusals.js +3 -3
  57. package/dist/commands/exec/run-bin.d.ts +1 -1
  58. package/dist/commands/exec/run-bin.js +2 -2
  59. package/dist/commands/exec/run-command.d.ts +345 -63
  60. package/dist/commands/exec/run-command.js +308 -258
  61. package/dist/commands/exec/run-metadata.d.ts +42 -8
  62. package/dist/commands/exec/run-metadata.js +40 -21
  63. package/dist/commands/exec/run-planned.d.ts +20 -0
  64. package/dist/commands/exec/run-planned.js +22 -0
  65. package/dist/commands/exec/sandbox-lines.d.ts +42 -0
  66. package/dist/commands/exec/sandbox-lines.js +59 -0
  67. package/dist/commands/exec/sandbox-progress.d.ts +30 -0
  68. package/dist/commands/exec/sandbox-progress.js +232 -0
  69. package/dist/commands/exec/sandbox-view.d.ts +19 -0
  70. package/dist/commands/exec/sandbox-view.js +72 -0
  71. package/dist/commands/exec/view.d.ts +3 -2
  72. package/dist/commands/exec/view.js +10 -6
  73. package/dist/commands/runs/facts.d.ts +51 -9
  74. package/dist/commands/runs/facts.js +49 -29
  75. package/dist/commands/runs/list/command.d.ts +80 -4
  76. package/dist/commands/runs/list/command.js +11 -10
  77. package/dist/commands/runs/list/metadata.js +1 -1
  78. package/dist/commands/runs/list/outcomes.d.ts +40 -2
  79. package/dist/commands/runs/logs/command.d.ts +103 -8
  80. package/dist/commands/runs/logs/command.js +139 -24
  81. package/dist/commands/runs/logs/metadata.d.ts +4 -0
  82. package/dist/commands/runs/logs/metadata.js +14 -7
  83. package/dist/commands/runs/logs/outcomes.d.ts +49 -2
  84. package/dist/commands/runs/logs/outcomes.js +110 -6
  85. package/dist/commands/runs/past-run.d.ts +77 -6
  86. package/dist/commands/runs/past-run.js +133 -4
  87. package/dist/commands/runs/show/command.d.ts +568 -10
  88. package/dist/commands/runs/show/command.js +634 -119
  89. package/dist/commands/runs/show/metadata.d.ts +17 -0
  90. package/dist/commands/runs/show/metadata.js +48 -7
  91. package/dist/commands/runs/show/outcomes.d.ts +276 -5
  92. package/dist/commands/runs/show/outcomes.js +484 -96
  93. package/dist/commands/snapshots/build/command.d.ts +109 -18
  94. package/dist/commands/snapshots/build/command.js +72 -36
  95. package/dist/commands/snapshots/build/metadata.d.ts +4 -0
  96. package/dist/commands/snapshots/build/metadata.js +5 -1
  97. package/dist/commands/snapshots/build/outcomes.d.ts +53 -8
  98. package/dist/commands/snapshots/build/outcomes.js +26 -3
  99. package/dist/commands/snapshots/list/command.d.ts +72 -7
  100. package/dist/commands/snapshots/list/command.js +57 -24
  101. package/dist/commands/snapshots/list/metadata.d.ts +4 -0
  102. package/dist/commands/snapshots/list/metadata.js +4 -0
  103. package/dist/commands/snapshots/list/outcomes.d.ts +31 -0
  104. package/dist/commands/snapshots/list/outcomes.js +25 -2
  105. package/dist/commands/suites/list/command.d.ts +129 -0
  106. package/dist/commands/suites/list/command.js +162 -0
  107. package/dist/commands/suites/list/metadata.d.ts +11 -0
  108. package/dist/commands/suites/list/metadata.js +15 -0
  109. package/dist/commands/suites/list/outcomes.d.ts +91 -0
  110. package/dist/commands/suites/list/outcomes.js +122 -0
  111. package/dist/commands/suites/metadata.js +8 -0
  112. package/dist/commands/test/command.d.ts +1389 -0
  113. package/dist/commands/test/command.js +583 -0
  114. package/dist/commands/test/metadata.js +8 -0
  115. package/dist/commands/test/outcomes.d.ts +765 -0
  116. package/dist/commands/test/outcomes.js +140 -0
  117. package/dist/commands/test/plan.d.ts +92 -0
  118. package/dist/commands/test/plan.js +128 -0
  119. package/dist/commands/test/test-words.d.ts +12 -0
  120. package/dist/commands/test/test-words.js +42 -0
  121. package/dist/config/check-resources.d.ts +14 -0
  122. package/dist/config/check-resources.js +98 -0
  123. package/dist/config/check-runner.d.ts +13 -0
  124. package/dist/config/check-runner.js +54 -0
  125. package/dist/config/check-suites.d.ts +14 -0
  126. package/dist/config/check-suites.js +99 -0
  127. package/dist/config/gateways.d.ts +24 -0
  128. package/dist/config/index.d.ts +6 -3
  129. package/dist/config/index.js +3 -1
  130. package/dist/config/live/file-lists-file-gateway.d.ts +4 -0
  131. package/dist/config/live/file-lists-file-gateway.js +27 -0
  132. package/dist/config/load.d.ts +11 -10
  133. package/dist/config/load.js +35 -103
  134. package/dist/config/recipe-run.d.ts +8 -1
  135. package/dist/config/recipe-run.js +2 -1
  136. package/dist/config/resolve.d.ts +3 -2
  137. package/dist/config/resolve.js +6 -3
  138. package/dist/config/resolver.d.ts +20 -6
  139. package/dist/config/resolver.js +11 -8
  140. package/dist/config/runner.d.ts +24 -0
  141. package/dist/config/runner.js +4 -0
  142. package/dist/config/schema.d.ts +26 -18
  143. package/dist/config/schema.js +41 -9
  144. package/dist/config/settings-file.d.ts +9 -3
  145. package/dist/config/settings-file.js +41 -4
  146. package/dist/config/suite.d.ts +39 -0
  147. package/dist/config/suite.js +5 -0
  148. package/dist/config-file/define.d.ts +49 -18
  149. package/dist/config-file/define.js +9 -8
  150. package/dist/config-file/runner.d.ts +12 -0
  151. package/dist/config-file/runner.js +9 -0
  152. package/dist/context.d.ts +13 -8
  153. package/dist/context.js +13 -4
  154. package/dist/core/across-sandboxes.d.ts +43 -0
  155. package/dist/core/across-sandboxes.js +319 -0
  156. package/dist/core/before-run.d.ts +5 -3
  157. package/dist/core/before-run.js +12 -1
  158. package/dist/core/events.d.ts +62 -6
  159. package/dist/core/events.js +14 -0
  160. package/dist/core/index.d.ts +4 -2
  161. package/dist/core/index.js +3 -1
  162. package/dist/core/payload.d.ts +7 -4
  163. package/dist/core/payload.js +10 -4
  164. package/dist/core/presentations.js +1 -1
  165. package/dist/core/resource.d.ts +1 -1
  166. package/dist/core/resources.d.ts +56 -6
  167. package/dist/core/resources.js +81 -5
  168. package/dist/core/run-state.js +9 -0
  169. package/dist/core/run.d.ts +77 -15
  170. package/dist/core/run.js +150 -86
  171. package/dist/core/sandbox-end.d.ts +64 -0
  172. package/dist/core/sandbox-end.js +128 -0
  173. package/dist/core/timeline.d.ts +4 -4
  174. package/dist/core/timeline.js +3 -3
  175. package/dist/credential/live/vercel-cli-gateway.d.ts +7 -0
  176. package/dist/credential/live/vercel-cli-gateway.js +14 -1
  177. package/dist/extensions/github/context.d.ts +1 -1
  178. package/dist/extensions/github/definition.d.ts +11 -9
  179. package/dist/extensions/github/definition.js +8 -6
  180. package/dist/extensions/github/extension.d.ts +3 -3
  181. package/dist/extensions/github/fixture-repo.d.ts +21 -2
  182. package/dist/extensions/github/fixture-repo.js +31 -2
  183. package/dist/extensions/github/index.d.ts +2 -2
  184. package/dist/extensions/github/index.js +2 -2
  185. package/dist/extensions/github/lifecycle.d.ts +16 -6
  186. package/dist/extensions/github/lifecycle.js +42 -25
  187. package/dist/extensions/github/options.d.ts +17 -11
  188. package/dist/extensions/github/options.js +14 -13
  189. package/dist/extensions/github/refusals.d.ts +23 -6
  190. package/dist/extensions/github/refusals.js +34 -12
  191. package/dist/extensions/github/resource.d.ts +21 -12
  192. package/dist/extensions/github/resource.js +16 -8
  193. package/dist/extensions/github/run/payload.d.ts +6 -6
  194. package/dist/extensions/github/run/payload.js +3 -5
  195. package/dist/extensions/github/split.d.ts +10 -0
  196. package/dist/extensions/github/split.js +12 -0
  197. package/dist/extensions/playwright/driver.js +6 -26
  198. package/dist/extensions/playwright/extension.js +1 -1
  199. package/dist/extensions/testserver/commands/pool/create/command.js +8 -8
  200. package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
  201. package/dist/extensions/testserver/definition.d.ts +4 -4
  202. package/dist/extensions/testserver/definition.js +41 -31
  203. package/dist/extensions/testserver/extension.d.ts +4 -5
  204. package/dist/extensions/testserver/extension.js +14 -41
  205. package/dist/extensions/testserver/index.d.ts +1 -1
  206. package/dist/extensions/testserver/index.js +1 -1
  207. package/dist/extensions/testserver/lifecycle.d.ts +10 -2
  208. package/dist/extensions/testserver/lifecycle.js +29 -6
  209. package/dist/extensions/testserver/options/rules.d.ts +5 -5
  210. package/dist/extensions/testserver/options/rules.js +10 -8
  211. package/dist/extensions/testserver/options/sandboxes.d.ts +4 -2
  212. package/dist/extensions/testserver/options/sandboxes.js +8 -3
  213. package/dist/extensions/testserver/pool/gateways.d.ts +29 -4
  214. package/dist/extensions/testserver/pool/index.d.ts +2 -2
  215. package/dist/extensions/testserver/pool/index.js +1 -1
  216. package/dist/extensions/testserver/pool/lease.d.ts +10 -0
  217. package/dist/extensions/testserver/pool/lease.js +21 -0
  218. package/dist/extensions/testserver/pool/live/pool-store-gateway.js +38 -3
  219. package/dist/extensions/testserver/refusals.d.ts +12 -0
  220. package/dist/extensions/testserver/refusals.js +18 -0
  221. package/dist/extensions/testserver/release.d.ts +16 -0
  222. package/dist/extensions/testserver/release.js +56 -4
  223. package/dist/extensions/testserver/resource.d.ts +4 -4
  224. package/dist/extensions/testserver/resource.js +1 -1
  225. package/dist/extensions/testserver/split.d.ts +9 -0
  226. package/dist/extensions/testserver/split.js +22 -0
  227. package/dist/extensions/testserver/vitest/fixtures.d.ts +5 -5
  228. package/dist/extensions/testserver/vitest/fixtures.js +9 -38
  229. package/dist/extensions/vitest/driver.d.ts +7 -0
  230. package/dist/extensions/vitest/driver.js +33 -37
  231. package/dist/extensions/vitest/extension.js +1 -1
  232. package/dist/extensions/vitest/plan/plan-over.d.ts +8 -1
  233. package/dist/extensions/vitest/plan/plan-over.js +16 -2
  234. package/dist/extensions.d.ts +17 -16
  235. package/dist/extensions.js +5 -4
  236. package/dist/forward-sigterm.js +1 -1
  237. package/dist/launcher-resolvers/local-services.d.ts +1 -1
  238. package/dist/live-app.d.ts +3 -1
  239. package/dist/live-app.js +9 -5
  240. package/dist/local-services.js +1 -1
  241. package/dist/planning/driver-file-lists.d.ts +61 -0
  242. package/dist/planning/driver-file-lists.js +66 -0
  243. package/dist/{commands/exec → planning}/driver-refusals.d.ts +11 -10
  244. package/dist/{commands/exec → planning}/driver-refusals.js +18 -14
  245. package/dist/planning/file-lists-file.d.ts +58 -0
  246. package/dist/planning/file-lists-file.js +105 -0
  247. package/dist/planning/file-lists.d.ts +28 -0
  248. package/dist/planning/file-lists.js +52 -0
  249. package/dist/{commands/exec → planning}/final-results.d.ts +1 -1
  250. package/dist/{commands/exec → planning}/final-results.js +6 -6
  251. package/dist/planning/plan-only.d.ts +81 -0
  252. package/dist/planning/plan-only.js +83 -0
  253. package/dist/{commands/exec → planning}/redaction.d.ts +2 -2
  254. package/dist/{commands/exec → planning}/redaction.js +5 -4
  255. package/dist/{commands/exec → planning}/resource-flags.d.ts +5 -12
  256. package/dist/{commands/exec → planning}/resource-flags.js +6 -16
  257. package/dist/planning/run-kind-flags.d.ts +20 -0
  258. package/dist/planning/run-kind-flags.js +48 -0
  259. package/dist/planning/run-plan.d.ts +30 -0
  260. package/dist/planning/run-plan.js +4 -0
  261. package/dist/planning/sandbox-placeholders.d.ts +22 -0
  262. package/dist/planning/sandbox-placeholders.js +60 -0
  263. package/dist/planning/suite-not-found.d.ts +37 -0
  264. package/dist/planning/suite-not-found.js +36 -0
  265. package/dist/planning/suites.d.ts +43 -0
  266. package/dist/planning/suites.js +89 -0
  267. package/dist/{commands/exec → planning}/test-plan.d.ts +8 -3
  268. package/dist/{commands/exec → planning}/test-plan.js +32 -4
  269. package/dist/playwright/reporter.d.ts +20 -8
  270. package/dist/playwright/reporter.js +195 -15
  271. package/dist/presentation.d.ts +10 -6
  272. package/dist/presentation.js +13 -15
  273. package/dist/run-directory/gateways.d.ts +60 -4
  274. package/dist/run-directory/index.d.ts +4 -4
  275. package/dist/run-directory/index.js +2 -1
  276. package/dist/run-directory/live/run-directory-gateway.js +92 -16
  277. package/dist/run-directory/plan.d.ts +35 -2
  278. package/dist/run-directory/plan.js +44 -7
  279. package/dist/run-directory/reader.d.ts +26 -5
  280. package/dist/run-directory/reader.js +24 -1
  281. package/dist/run-directory/recording.d.ts +75 -49
  282. package/dist/run-directory/recording.js +214 -28
  283. package/dist/run-directory/run-directory.d.ts +22 -1
  284. package/dist/run-directory/run-directory.js +24 -0
  285. package/dist/run-directory/run-record.d.ts +144 -21
  286. package/dist/run-directory/run-record.js +118 -19
  287. package/dist/run-directory/timeline-facts.js +4 -4
  288. package/dist/runner/build-snapshots.d.ts +7 -7
  289. package/dist/runner/build-snapshots.js +12 -16
  290. package/dist/runner/events.d.ts +29 -8
  291. package/dist/runner/gateways.d.ts +59 -8
  292. package/dist/runner/index.d.ts +6 -4
  293. package/dist/runner/index.js +3 -2
  294. package/dist/runner/live/sandbox-gateway.js +177 -33
  295. package/dist/runner/live/terminal.d.ts +15 -3
  296. package/dist/runner/live/terminal.js +25 -3
  297. package/dist/runner/network-policy.d.ts +55 -0
  298. package/dist/runner/network-policy.js +46 -0
  299. package/dist/runner/policy-writes.d.ts +40 -0
  300. package/dist/runner/policy-writes.js +124 -0
  301. package/dist/runner/prepare.d.ts +6 -7
  302. package/dist/runner/ready.d.ts +39 -10
  303. package/dist/runner/ready.js +59 -47
  304. package/dist/runner/recipe-check.d.ts +6 -0
  305. package/dist/runner/recipe-check.js +29 -0
  306. package/dist/runner/recipe-secrets.d.ts +67 -0
  307. package/dist/runner/recipe-secrets.js +230 -0
  308. package/dist/runner/recipe.d.ts +118 -28
  309. package/dist/runner/recipe.js +147 -154
  310. package/dist/runner/sandboxed-command.d.ts +24 -10
  311. package/dist/runner/sandboxed-command.js +37 -12
  312. package/dist/runner/scope.d.ts +107 -21
  313. package/dist/runner/scope.js +274 -54
  314. package/dist/runner/secrets.d.ts +42 -31
  315. package/dist/runner/secrets.js +62 -40
  316. package/dist/runner/session.d.ts +59 -26
  317. package/dist/runner/session.js +82 -41
  318. package/dist/runner/snapshot-build.d.ts +7 -4
  319. package/dist/runner/snapshot-build.js +48 -28
  320. package/dist/runner/snapshot-choice.d.ts +37 -0
  321. package/dist/runner/snapshot-choice.js +38 -0
  322. package/dist/runner/snapshot-key.d.ts +16 -14
  323. package/dist/runner/snapshot-key.js +24 -18
  324. package/dist/runner/steps.d.ts +13 -5
  325. package/dist/runner/steps.js +34 -4
  326. package/dist/runner/time-limit.d.ts +10 -0
  327. package/dist/runner/time-limit.js +43 -0
  328. package/dist/sdk/extension/commands.d.ts +1 -7
  329. package/dist/sdk/extension/driver.d.ts +39 -46
  330. package/dist/sdk/extension/driver.js +6 -6
  331. package/dist/sdk/extension/index.d.ts +3 -3
  332. package/dist/sdk/extension/index.js +3 -4
  333. package/dist/sdk/extension/lifecycle.d.ts +52 -9
  334. package/dist/sdk/extension/lifecycle.js +1 -1
  335. package/dist/sdk/extension/resource-definition.d.ts +13 -10
  336. package/dist/sdk/extension/resource-definition.js +7 -2
  337. package/dist/sdk/extension/resource.d.ts +2 -2
  338. package/dist/sdk/extension/secret-source.d.ts +58 -0
  339. package/dist/sdk/extension/secret-source.js +78 -0
  340. package/dist/sdk/index.d.ts +2 -2
  341. package/dist/sdk/index.js +1 -1
  342. package/dist/sdk/run/launcher.d.ts +1 -1
  343. package/dist/sdk/run/launcher.js +1 -1
  344. package/dist/sdk/run/payload.d.ts +16 -1
  345. package/dist/sdk/run/payload.js +17 -2
  346. package/dist/sdk/run/redact.js +2 -2
  347. package/dist/sdk/run/test-events.d.ts +23 -6
  348. package/dist/sdk/run/test-events.js +6 -4
  349. package/dist/sdk/run/test-result-writer.d.ts +8 -3
  350. package/dist/sdk/run/test-result-writer.js +22 -2
  351. package/dist/{commands/exec → shared}/cleanup.d.ts +3 -3
  352. package/dist/{commands/exec → shared}/cleanup.js +11 -6
  353. package/dist/shared/job-summary.d.ts +19 -0
  354. package/dist/{commands/exec → shared}/job-summary.js +17 -0
  355. package/dist/shared/sandbox-table.d.ts +48 -0
  356. package/dist/shared/sandbox-table.js +109 -0
  357. package/dist/{commands/exec → shared}/snapshot-text.d.ts +1 -1
  358. package/dist/{commands/exec → shared}/tests-summary.d.ts +22 -6
  359. package/dist/{commands/exec → shared}/tests-summary.js +74 -31
  360. package/dist/{commands/exec → shared}/text.d.ts +7 -2
  361. package/dist/{commands/exec → shared}/text.js +9 -1
  362. package/dist/{commands/exec → shared}/waterfall.d.ts +8 -6
  363. package/dist/{commands/exec → shared}/waterfall.js +71 -24
  364. package/dist/shared/worker-chart.d.ts +172 -0
  365. package/dist/shared/worker-chart.js +623 -0
  366. package/dist/vitest/config.d.ts +35 -11
  367. package/dist/vitest/config.js +47 -14
  368. package/dist/vitest/index.d.ts +1 -1
  369. package/dist/vitest/index.js +3 -3
  370. package/dist/vitest/sequencer.d.ts +23 -0
  371. package/dist/vitest/sequencer.js +73 -0
  372. package/dist/vitest/setup.d.ts +1 -0
  373. package/dist/vitest/setup.js +34 -0
  374. package/dist/vitest/test-events.d.ts +32 -6
  375. package/dist/vitest/test-events.js +25 -5
  376. package/dist/vitest/test-results.d.ts +8 -3
  377. package/dist/vitest/test-results.js +6 -0
  378. package/package.json +7 -2
  379. package/skills/overview.md +21 -17
  380. package/skills/plan-runs.md +67 -0
  381. package/skills/read-run-output.md +51 -19
  382. package/dist/chunks/chunk-BFLYGMG3.js +0 -607
  383. package/dist/chunks/chunk-HOKDKP5A.js +0 -49
  384. package/dist/chunks/chunk-IVRRGGCD.js +0 -201
  385. package/dist/chunks/chunk-NMVODY3P.js +0 -19
  386. package/dist/commands/exec/define-run-command.d.ts +0 -671
  387. package/dist/commands/exec/define-run-command.js +0 -91
  388. package/dist/commands/exec/job-summary.d.ts +0 -10
  389. package/dist/commands/exec/worker-chart.d.ts +0 -87
  390. package/dist/commands/exec/worker-chart.js +0 -343
  391. package/dist/commands/playwright/command.d.ts +0 -661
  392. package/dist/commands/playwright/command.js +0 -31
  393. package/dist/commands/playwright/metadata.js +0 -8
  394. package/dist/commands/vitest/command.d.ts +0 -662
  395. package/dist/commands/vitest/command.js +0 -31
  396. package/dist/commands/vitest/metadata.js +0 -8
  397. package/dist/sdk/extension/ci.d.ts +0 -2
  398. package/dist/sdk/extension/ci.js +0 -6
  399. package/dist/chunks/{chunk-YM6TZV4L.js → chunk-VL7WFTVQ.js} +52 -52
  400. package/dist/commands/{playwright → suites}/metadata.d.ts +1 -1
  401. package/dist/commands/{vitest → test}/metadata.d.ts +1 -1
  402. /package/dist/{commands → shared}/dashboard.d.ts +0 -0
  403. /package/dist/{commands → shared}/dashboard.js +0 -0
  404. /package/dist/{commands/exec → shared}/snapshot-text.js +0 -0
@@ -1,20 +1,26 @@
1
1
  import {
2
2
  Credential,
3
+ ENV_VAR_NAME_PATTERN,
4
+ ENV_VAR_NAME_RULE,
3
5
  NOT_COUNTED,
4
6
  booleanOption,
5
7
  defaultResourceKey,
6
8
  describeMintFailure,
9
+ describeSecretSource,
7
10
  describeValue,
8
11
  nonEmptyString,
9
12
  optionKeyPath,
13
+ readSecretSource,
14
+ readSecretSourceValue,
10
15
  resourceCall,
16
+ secretSourceId,
11
17
  tokenRequestFailureFacts,
12
18
  tokenRequestFailureShape
13
- } from "./chunk-RA4L2ACU.js";
19
+ } from "./chunk-AWBSONHB.js";
14
20
  import {
15
21
  defineErrors,
16
22
  refused
17
- } from "./chunk-YM6TZV4L.js";
23
+ } from "./chunk-VL7WFTVQ.js";
18
24
 
19
25
  // src/config/credential-settle.ts
20
26
  import { z } from "zod";
@@ -56,36 +62,6 @@ function settleCredential(source, scope, project) {
56
62
  return { ok: true, credential: { source, target: required.target } };
57
63
  }
58
64
 
59
- // src/runner/secrets.ts
60
- var RUNNER_SECRET_MIN_LENGTH = 8;
61
- function stepSecrets(values, names) {
62
- return Object.fromEntries(
63
- names.map((name) => {
64
- const value = ownValue(values, name);
65
- if (value === void 0) throw new Error(`stepSecrets: no value for runner secret ${name}`);
66
- return [name, value];
67
- })
68
- );
69
- }
70
- function declaredSecretValues(recipe, env) {
71
- return (recipe?.secrets ?? []).map((name) => ownValue(env, name)).filter((value) => value !== void 0 && value !== "");
72
- }
73
- function readRunnerSecrets(recipe, env) {
74
- const values = [];
75
- const variables = [];
76
- for (const name of recipe.secrets) {
77
- const value = ownValue(env, name);
78
- if (value === void 0 || value === "") variables.push({ name, problem: "missing" });
79
- else if (/[\r\n]/.test(value)) variables.push({ name, problem: "multiline" });
80
- else if (value.length < RUNNER_SECRET_MIN_LENGTH) variables.push({ name, problem: "short" });
81
- else values.push([name, value]);
82
- }
83
- return variables.length === 0 ? { ok: true, values: Object.fromEntries(values) } : { ok: false, variables };
84
- }
85
- function ownValue(map, name) {
86
- return Object.hasOwn(map, name) ? map[name] : void 0;
87
- }
88
-
89
65
  // src/runner/base.ts
90
66
  async function resolveBase(checkout, request2) {
91
67
  const { repoRoot } = request2;
@@ -126,94 +102,388 @@ function baseStepContext(checkout, request2) {
126
102
  };
127
103
  }
128
104
 
105
+ // src/runner/time-limit.ts
106
+ function callWithin(timer, ms, call) {
107
+ const abort = new AbortController();
108
+ const limit = new AbortController();
109
+ return new Promise((resolve, reject) => {
110
+ call(abort.signal).then(
111
+ (answer) => {
112
+ limit.abort();
113
+ resolve(answer);
114
+ },
115
+ (error) => {
116
+ limit.abort();
117
+ reject(error);
118
+ }
119
+ );
120
+ void timer.sleep(ms, limit.signal).then(() => {
121
+ if (limit.signal.aborted) return;
122
+ abort.abort();
123
+ resolve(null);
124
+ });
125
+ });
126
+ }
127
+ var ABORTED = /* @__PURE__ */ Symbol("aborted");
128
+ function untilAborted(promise, signal) {
129
+ if (signal.aborted) return Promise.resolve(ABORTED);
130
+ return new Promise((resolve, reject) => {
131
+ const onAbort = () => resolve(ABORTED);
132
+ signal.addEventListener("abort", onAbort, { once: true });
133
+ promise.then(
134
+ (answer) => {
135
+ signal.removeEventListener("abort", onAbort);
136
+ resolve(answer);
137
+ },
138
+ (error) => {
139
+ signal.removeEventListener("abort", onAbort);
140
+ reject(error);
141
+ }
142
+ );
143
+ });
144
+ }
145
+
146
+ // src/runner/network-policy.ts
147
+ var NETWORK_POLICY_WRITE_LIMIT_MS = 1e4;
148
+ function runnerNetworkPolicy(recipe) {
149
+ if (recipe.allowedDomains === void 0) return { kind: "allow-all", credentials: [] };
150
+ return { kind: "custom", allowedDomains: [...recipe.allowedDomains], credentials: [] };
151
+ }
152
+ function withCredentials(base, credentials2) {
153
+ return { ...base, credentials: credentials2 };
154
+ }
155
+ function denyAllPolicy() {
156
+ return { kind: "deny-all" };
157
+ }
158
+ function policyCredentials(policy) {
159
+ return policy.kind === "deny-all" ? [] : policy.credentials;
160
+ }
161
+ async function replaceNetworkPolicy(context, sandbox, policy) {
162
+ const answered = await callWithin(
163
+ context.timer,
164
+ NETWORK_POLICY_WRITE_LIMIT_MS,
165
+ (signal) => context.runnerSandboxes.writeNetworkPolicy(sandbox, policy, signal)
166
+ );
167
+ return answered ?? { ok: false, failure: { kind: "timed-out", limitMs: NETWORK_POLICY_WRITE_LIMIT_MS } };
168
+ }
169
+
170
+ // src/runner/policy-writes.ts
171
+ function sandboxPolicyWriter(context, basePolicy, onTimedOut) {
172
+ const states = /* @__PURE__ */ new Map();
173
+ const stateOf = (sandbox) => {
174
+ let state2 = states.get(sandbox);
175
+ if (state2 === void 0) {
176
+ state2 = { last: Promise.resolve(), mayInject: false, timedOut: false, removal: null };
177
+ states.set(sandbox, state2);
178
+ }
179
+ return state2;
180
+ };
181
+ const mayInject = (sandbox) => states.get(sandbox)?.mayInject === true;
182
+ const send = (sandbox, policy, signal) => {
183
+ if (signal?.aborted === true) return Promise.resolve({ ok: false, failure: { kind: "aborted" } });
184
+ const state2 = stateOf(sandbox);
185
+ const injects = policyCredentials(policy).length > 0;
186
+ if (injects) state2.mayInject = true;
187
+ const turn = state2.last;
188
+ let release = () => {
189
+ };
190
+ const mine = new Promise((resolve) => {
191
+ release = resolve;
192
+ });
193
+ state2.last = mine;
194
+ const answer = (async () => {
195
+ if (!await untilTurn(turn, signal)) {
196
+ void turn.then(release);
197
+ return { ok: false, failure: { kind: "aborted" } };
198
+ }
199
+ try {
200
+ if (state2.timedOut) return { ok: false, failure: timedOut() };
201
+ const answered = await replaceNetworkPolicy(context, sandbox, policy);
202
+ if (answered.ok) {
203
+ if (!injects && state2.last === mine) state2.mayInject = false;
204
+ } else if (answered.failure.kind === "timed-out") {
205
+ state2.timedOut = true;
206
+ onTimedOut(sandbox, answered.failure);
207
+ }
208
+ return answered;
209
+ } finally {
210
+ release();
211
+ }
212
+ })();
213
+ const removal = !injects && signal === void 0 ? answer : null;
214
+ state2.removal = removal;
215
+ if (removal !== null) {
216
+ const forget = () => {
217
+ if (state2.removal === removal) state2.removal = null;
218
+ };
219
+ void removal.then(forget, forget);
220
+ }
221
+ return answer;
222
+ };
223
+ return {
224
+ write: send,
225
+ removeInjections: (sandbox) => states.get(sandbox)?.removal ?? send(sandbox, basePolicy, void 0),
226
+ mayInject,
227
+ injectingSandboxes: () => [...states.keys()].filter(mayInject)
228
+ };
229
+ }
230
+ function notRemovedMessage(failure) {
231
+ return failure.kind === "timed-out" ? `its network policy may still hold a credential: a policy write had no answer within ${failure.limitMs / 1e3} seconds and may still take effect, so no write can remove the credential for certain` : `its network policy may still hold a credential: removing the credential failed (${writeFailureMessage(failure)})`;
232
+ }
233
+ function notFencedMessage(failure, injecting) {
234
+ return injecting ? notRemovedMessage(failure) : `giving it no network access failed (${writeFailureMessage(failure)})`;
235
+ }
236
+ function timedOut() {
237
+ return { kind: "timed-out", limitMs: NETWORK_POLICY_WRITE_LIMIT_MS };
238
+ }
239
+ async function untilTurn(turn, signal) {
240
+ if (signal === void 0) {
241
+ await turn;
242
+ return true;
243
+ }
244
+ return await untilAborted(turn, signal) !== ABORTED;
245
+ }
246
+ function writeFailureMessage(failure) {
247
+ if (failure.kind === "timed-out") return `no answer within ${failure.limitMs / 1e3} seconds`;
248
+ if (failure.kind === "aborted") return "aborted";
249
+ return failure.status === void 0 ? failure.message : `HTTP ${failure.status}: ${failure.message}`;
250
+ }
251
+
129
252
  // src/runner/scope.ts
130
253
  var CREATE_SETTLE_MS = 2e4;
131
254
  var SNAPSHOT_SETTLE_MS = 2 * 6e4;
132
- function runnerSandboxScope(context, progress, keep) {
255
+ var SANDBOX_CALL_LIMIT_MS = 3e4;
256
+ var KEEP_RUNNING_LIMIT_MS = 6e4;
257
+ function runnerSandboxScope(context, progress, settings) {
133
258
  const { runnerSandboxes: sandboxes, timer, clock } = context;
134
- const live = /* @__PURE__ */ new Set();
135
- const creating = /* @__PURE__ */ new Set();
259
+ let phase = { kind: "open", sandboxes: /* @__PURE__ */ new Map(), creating: /* @__PURE__ */ new Set() };
136
260
  const saving = /* @__PURE__ */ new Set();
137
261
  const notStopped = [];
138
262
  const notDeleted = [];
139
263
  let kept = null;
140
264
  let notKept = null;
141
- let closing;
265
+ let settling;
266
+ let stoppingOthers;
267
+ let stoppingUnkept;
268
+ let removingOnSignal;
269
+ let fencing;
270
+ let closingScope;
271
+ const stops = /* @__PURE__ */ new Map();
272
+ const isStopping = (sandbox) => stops.has(sandbox);
273
+ const currentPhase = () => phase;
274
+ const beginClosing = () => {
275
+ if (phase.kind === "open") phase = { kind: "settling", sandboxes: phase.sandboxes, creating: phase.creating };
276
+ };
142
277
  const track = (set, task) => {
143
278
  set.add(task);
144
279
  const forget = () => set.delete(task);
145
280
  void task.then(forget, forget);
146
281
  return task;
147
282
  };
148
- const remove = async (sandbox) => {
149
- const deleted = await sandboxes.delete(sandbox);
150
- if (!deleted.ok)
151
- notDeleted.push({ name: sandbox.name, role: sandbox.role, message: failureMessage(deleted.failure) });
283
+ const recordNotKept = (sandbox, message) => {
284
+ notKept ??= { name: sandbox.name, message };
152
285
  };
153
- const stopAndRemove = async (sandbox) => {
154
- const stopped = await sandboxes.stop(sandbox);
155
- if (!stopped.ok) {
156
- notStopped.push({
286
+ const deleteSandbox = async (sandbox) => {
287
+ const deleted = await callWithin(timer, SANDBOX_CALL_LIMIT_MS, (signal) => sandboxes.delete(sandbox, signal));
288
+ if (deleted === null || !deleted.ok)
289
+ notDeleted.push({
157
290
  name: sandbox.name,
158
291
  role: sandbox.role,
159
- timeoutMinutes: Math.round(sandbox.timeoutMs / 6e4),
160
- message: failureMessage(stopped.failure)
292
+ message: callFailureMessage(deleted, SANDBOX_CALL_LIMIT_MS)
161
293
  });
162
- return;
294
+ };
295
+ const stop = (sandbox) => {
296
+ let stopping = stops.get(sandbox);
297
+ if (stopping === void 0) {
298
+ stopping = (async () => {
299
+ const answer = await callWithin(timer, SANDBOX_CALL_LIMIT_MS, (signal) => sandboxes.stop(sandbox, signal));
300
+ if (answer !== null && answer.ok) return true;
301
+ notStopped.push({
302
+ name: sandbox.name,
303
+ role: sandbox.role,
304
+ timeoutMinutes: Math.round(sandbox.timeoutMs / 6e4),
305
+ message: callFailureMessage(answer, SANDBOX_CALL_LIMIT_MS)
306
+ });
307
+ return false;
308
+ })();
309
+ stops.set(sandbox, stopping);
310
+ }
311
+ return stopping;
312
+ };
313
+ const giveUp = (sandbox, message) => {
314
+ const entry = phase.sandboxes.get(sandbox);
315
+ if (entry?.keep === true) {
316
+ if (message !== void 0) recordNotKept(sandbox, message);
317
+ entry.keep = false;
318
+ }
319
+ return stop(sandbox);
320
+ };
321
+ const policies = sandboxPolicyWriter(context, settings.basePolicy, (sandbox, failure) => {
322
+ void giveUp(sandbox, notFencedMessage(failure, policies.mayInject(sandbox)));
323
+ });
324
+ const stopAndDelete = async (sandbox) => {
325
+ if (await stop(sandbox)) await deleteSandbox(sandbox);
326
+ };
327
+ const stopUnkeptSandbox = async (sandbox) => {
328
+ if (policies.mayInject(sandbox)) await revoke(sandbox);
329
+ await stop(sandbox);
330
+ };
331
+ const fenceKept = async (entry) => {
332
+ const { sandbox } = entry;
333
+ await removingOnSignal;
334
+ let message;
335
+ if (!isStopping(sandbox)) {
336
+ const injecting = policies.mayInject(sandbox);
337
+ const written = await policies.write(sandbox, denyAllPolicy());
338
+ if (!isStopping(sandbox)) {
339
+ if (written.ok) return;
340
+ message = notFencedMessage(written.failure, injecting);
341
+ }
163
342
  }
164
- await remove(sandbox);
343
+ await giveUp(sandbox, message);
165
344
  };
166
- const keepOrRemove = async (sandbox) => {
167
- const keepMs = sandbox.role === "runner" ? keep.keepMs : 0;
168
- if (keepMs <= 0) return await stopAndRemove(sandbox);
169
- const keeping = await sandboxes.keepRunning(sandbox, { until: new Date(clock.now().getTime() + keepMs) });
170
- if (!keeping.ok) {
171
- notKept = { name: sandbox.name, message: failureMessage(keeping.failure) };
172
- return await stopAndRemove(sandbox);
345
+ const revoke = async (sandbox) => {
346
+ let message;
347
+ if (!isStopping(sandbox)) {
348
+ const removed = await policies.removeInjections(sandbox);
349
+ if (removed.ok) return;
350
+ message = notRemovedMessage(removed.failure);
351
+ }
352
+ await giveUp(sandbox, message);
353
+ };
354
+ const revokeEach = async (injecting) => {
355
+ await Promise.allSettled(injecting.map(revoke));
356
+ };
357
+ const keepOrDelete = async (sandbox) => {
358
+ if (isStopping(sandbox)) return await stopAndDelete(sandbox);
359
+ const until = new Date(clock.now().getTime() + settings.keepMs);
360
+ const keeping = await callWithin(
361
+ timer,
362
+ KEEP_RUNNING_LIMIT_MS,
363
+ (signal) => sandboxes.keepRunning(sandbox, { until }, signal)
364
+ );
365
+ if (keeping === null || !keeping.ok) {
366
+ recordNotKept(sandbox, callFailureMessage(keeping, KEEP_RUNNING_LIMIT_MS));
367
+ return await stopAndDelete(sandbox);
173
368
  }
174
369
  kept = { name: sandbox.name, stopsAt: keeping.value.stopsAt.toISOString() };
175
370
  await progress.emit({ kind: "sandbox-kept", ...kept });
176
371
  };
177
- const owned = (start) => {
178
- if (closing !== void 0) return Promise.resolve({ ok: false, failure: { kind: "aborted" } });
372
+ const settle = () => {
373
+ beginClosing();
374
+ return settling ??= (async () => {
375
+ if (phase.kind === "closing") return phase.sandboxes;
376
+ const { creating, sandboxes: entries } = phase;
377
+ if (saving.size > 0) await progress.emit({ kind: "waiting-for-snapshot", settleMs: SNAPSHOT_SETTLE_MS });
378
+ await Promise.all([
379
+ settleWithin(timer, creating, CREATE_SETTLE_MS),
380
+ settleWithin(timer, saving, SNAPSHOT_SETTLE_MS)
381
+ ]);
382
+ phase = { kind: "closing", sandboxes: entries };
383
+ return entries;
384
+ })();
385
+ };
386
+ const stopOthers = () => {
387
+ const entries = settle();
388
+ return stoppingOthers ??= (async () => {
389
+ const unkept = [...(await entries).values()].filter((entry) => !entry.keep);
390
+ await Promise.all(unkept.map(({ sandbox }) => stopUnkeptSandbox(sandbox)));
391
+ })();
392
+ };
393
+ const stopUnkept = () => stoppingUnkept ??= (async () => {
394
+ beginClosing();
395
+ removingOnSignal = revokeEach(policies.injectingSandboxes());
396
+ await Promise.all([removingOnSignal, stopOthers()]);
397
+ })();
398
+ const fence = () => {
399
+ const settled = settle();
400
+ return fencing ??= (async () => {
401
+ const entries = await settled;
402
+ const keptEntry = [...entries.values()].find((entry) => entry.keep);
403
+ await Promise.all([stopOthers(), keptEntry === void 0 ? void 0 : fenceKept(keptEntry)]);
404
+ await removingOnSignal;
405
+ return { runnerSandboxFenced: !notStopped.some(({ role }) => role === "runner") };
406
+ })().finally(() => settings.signal.removeEventListener("abort", onSignal));
407
+ };
408
+ const writable = () => phase.kind === "open";
409
+ const refused2 = { ok: false, failure: { kind: "aborted" } };
410
+ const revokeCredentials = async (sandbox) => {
411
+ if (!writable()) return refused2;
412
+ if (!policies.mayInject(sandbox)) return { ok: true };
413
+ return await policies.removeInjections(sandbox);
414
+ };
415
+ const grantCredentials = async (sandbox, credentials2, signal) => {
416
+ if (!writable() || signal.aborted) return refused2;
417
+ const granted = await policies.write(sandbox, withCredentials(settings.basePolicy, credentials2), signal);
418
+ if (signal.aborted || !writable()) {
419
+ await revokeCredentials(sandbox);
420
+ return refused2;
421
+ }
422
+ if (!granted.ok) await revokeCredentials(sandbox);
423
+ return granted;
424
+ };
425
+ const owned = (start, canKeep = false) => {
426
+ if (phase.kind !== "open") return Promise.resolve({ ok: false, failure: { kind: "aborted" } });
179
427
  return track(
180
- creating,
428
+ phase.creating,
181
429
  (async () => {
182
430
  const started = await start();
183
431
  if (!started.ok) return started;
184
- if (closing !== void 0) {
185
- await stopAndRemove(started.value);
186
- return { ok: false, failure: { kind: "aborted" } };
432
+ const now = currentPhase();
433
+ switch (now.kind) {
434
+ case "open":
435
+ now.sandboxes.set(started.value, { sandbox: started.value, keep: canKeep && settings.keepMs > 0 });
436
+ return started;
437
+ case "settling":
438
+ now.sandboxes.set(started.value, { sandbox: started.value, keep: false });
439
+ return { ok: false, failure: { kind: "aborted" } };
440
+ case "closing":
441
+ await stopAndDelete(started.value);
442
+ return { ok: false, failure: { kind: "aborted" } };
187
443
  }
188
- live.add(started.value);
189
- return started;
190
444
  })()
191
445
  );
192
446
  };
447
+ function onSignal() {
448
+ const commandRunning = settings.commandRunning?.() ?? false;
449
+ void progress.emit({ kind: "stopping", commandRunning, keepMs: settings.keepMs }).catch(() => void 0);
450
+ void stopUnkept().catch(() => void 0);
451
+ }
452
+ if (settings.signal.aborted) onSignal();
453
+ else settings.signal.addEventListener("abort", onSignal, { once: true });
193
454
  return {
194
- startBuildSandbox: (access, request2) => owned(() => sandboxes.startBuildSandbox(access, request2)),
195
- startRunnerSandbox: (access, request2) => owned(() => sandboxes.startRunnerSandbox(access, request2)),
455
+ startBuildSandbox: (access, request2) => owned(() => sandboxes.startBuildSandbox(access, { ...request2, networkPolicy: settings.basePolicy })),
456
+ startRunnerSandbox: (access, request2) => owned(() => sandboxes.startRunnerSandbox(access, { ...request2, networkPolicy: settings.basePolicy }), true),
457
+ grantCredentials,
458
+ revokeCredentials,
196
459
  saveSnapshot: (sandbox, request2) => track(
197
460
  saving,
198
461
  (async () => {
462
+ if (policies.mayInject(sandbox)) {
463
+ const removed = await policies.removeInjections(sandbox);
464
+ if (!removed.ok)
465
+ return { ok: false, failure: { kind: "credential-not-revoked", failure: removed.failure } };
466
+ }
199
467
  const saved = await sandboxes.saveSnapshot(sandbox, request2);
200
- if (saved.ok && live.delete(sandbox)) await remove(sandbox);
468
+ const now = currentPhase();
469
+ if (saved.ok && now.kind !== "closing" && now.sandboxes.delete(sandbox)) await deleteSandbox(sandbox);
201
470
  return saved;
202
471
  })()
203
472
  ),
473
+ fence,
204
474
  close() {
205
- closing ??= (async () => {
206
- if (saving.size > 0) await progress.emit({ kind: "waiting-for-snapshot", settleMs: SNAPSHOT_SETTLE_MS });
207
- await Promise.all([
208
- settleWithin(timer, creating, CREATE_SETTLE_MS),
209
- settleWithin(timer, saving, SNAPSHOT_SETTLE_MS)
210
- ]);
211
- const held = [...live];
212
- live.clear();
213
- await Promise.all(held.map(keepOrRemove));
475
+ beginClosing();
476
+ closingScope ??= (async () => {
477
+ await fence();
478
+ const entries = await settle();
479
+ await Promise.all(
480
+ [...entries.values()].map(
481
+ (entry) => entry.keep ? keepOrDelete(entry.sandbox) : stopAndDelete(entry.sandbox)
482
+ )
483
+ );
214
484
  return { kept, notKept, notStopped: [...notStopped], notDeleted: [...notDeleted] };
215
485
  })();
216
- return closing;
486
+ return closingScope;
217
487
  }
218
488
  };
219
489
  }
@@ -226,6 +496,9 @@ async function settleWithin(timer, tasks, ms) {
226
496
  function failureMessage(failure) {
227
497
  return failure.message ?? failure.kind;
228
498
  }
499
+ function callFailureMessage(answer, limitMs) {
500
+ return answer === null ? `no answer within ${limitMs / 1e3} seconds` : failureMessage(answer.failure);
501
+ }
229
502
 
230
503
  // src/runner/context.ts
231
504
  function runnerPurpose(recipeName) {
@@ -365,26 +638,34 @@ var systemClock = {
365
638
  import { z as z2 } from "zod";
366
639
  var RUN_PAYLOAD_VARIABLE = "STORM_RUN";
367
640
  var RUN_PAYLOAD_VERSION = 3;
641
+ var runPayloadSandboxSchema = z2.object({
642
+ index: z2.number().int().nonnegative(),
643
+ count: z2.number().int().positive(),
644
+ files: z2.array(z2.string().min(1)).optional()
645
+ });
368
646
  var runPayloadSchema = z2.object({
369
647
  version: z2.literal(RUN_PAYLOAD_VERSION),
370
648
  resources: z2.record(z2.string(), z2.object({ definition: z2.string().min(1), payload: z2.unknown() })),
371
649
  testEvents: z2.string().min(1).optional(),
372
- verbose: z2.literal(true).optional()
650
+ verbose: z2.literal(true).optional(),
651
+ sandbox: runPayloadSandboxSchema.optional()
373
652
  });
374
653
 
375
654
  // src/sdk/run/test-events.ts
376
655
  import { z as z3 } from "zod";
377
656
  var where = { file: z3.string(), worker: z3.number().int().nonnegative(), at: z3.number() };
657
+ var fileWhere = { file: z3.string(), worker: z3.number().int().nonnegative().exactOptional(), at: z3.number() };
658
+ var attempt = { id: z3.string().min(1), test: z3.string() };
378
659
  var setup = { label: z3.string().min(1), resource: z3.string().min(1) };
379
660
  var state = z3.enum(["pass", "fail", "skip"]);
380
661
  var testEventSchema = z3.discriminatedUnion("kind", [
381
- z3.object({ kind: z3.literal("file-started"), ...where }),
382
- z3.object({ kind: z3.literal("file-finished"), ...where }),
383
- z3.object({ kind: z3.literal("test-started"), ...where, test: z3.string(), fileTests: z3.number().int().nonnegative() }),
662
+ z3.object({ kind: z3.literal("file-started"), ...fileWhere }),
663
+ z3.object({ kind: z3.literal("file-finished"), ...fileWhere }),
664
+ z3.object({ kind: z3.literal("test-started"), ...where, ...attempt, fileTests: z3.number().int().nonnegative() }),
384
665
  z3.object({
385
666
  kind: z3.literal("test-attempt-finished"),
386
667
  ...where,
387
- test: z3.string(),
668
+ ...attempt,
388
669
  state,
389
670
  ms: z3.number().nonnegative()
390
671
  }),
@@ -438,106 +719,230 @@ function redactSecrets(text, secrets) {
438
719
  return ordered.reduce((redacted, secret) => redacted.split(secret).join(REDACTED), text);
439
720
  }
440
721
 
441
- // src/runner/events.ts
442
- function progressQueue(progress) {
443
- let pending = Promise.resolve();
444
- return {
445
- add(event) {
446
- pending = pending.then(() => progress.emit(event));
447
- },
448
- flush: () => pending
449
- };
450
- }
451
-
452
- // src/runner/output.ts
453
- var OUTPUT_TAIL_LINES = 40;
454
- function lineSplitter() {
455
- let buffer = "";
456
- return {
457
- push(chunk) {
458
- const end = chunk.lastIndexOf("\n");
459
- if (end === -1) {
460
- buffer += chunk;
461
- return "";
462
- }
463
- const lines = buffer + chunk.slice(0, end + 1);
464
- buffer = chunk.slice(end + 1);
465
- return lines;
466
- },
467
- flush() {
468
- const rest = buffer;
469
- buffer = "";
470
- return rest;
722
+ // src/runner/recipe-check.ts
723
+ function reportUnknownKeys(value, known, path, what, report) {
724
+ let ok = true;
725
+ for (const key of Object.keys(value))
726
+ if (!known.has(key)) {
727
+ report([...path, key], `is not ${what}`);
728
+ ok = false;
471
729
  }
472
- };
730
+ return ok;
473
731
  }
474
- function rewritePaths(text, fromRoot, toRoot) {
475
- const from = `${fromRoot.replace(/\/+$/, "")}/`;
476
- const to = `${toRoot.replace(/\/+$/, "")}/`;
477
- return text.split(from).join(to);
732
+ function describeRecipeValue(value) {
733
+ if (typeof value === "string") return JSON.stringify(value);
734
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
735
+ if (value === null) return "null";
736
+ if (value === void 0) return "undefined";
737
+ if (typeof value === "function") return "a function";
738
+ if (Array.isArray(value)) return value.length === 0 ? "an empty array" : "an array";
739
+ if (typeof value === "object") return "an object";
740
+ return `a ${typeof value}`;
478
741
  }
479
- function outputTail(limit = OUTPUT_TAIL_LINES) {
480
- const kept = [];
481
- return {
482
- add(line) {
483
- kept.push(line);
484
- if (kept.length > limit) kept.shift();
485
- },
486
- lines: () => [...kept]
487
- };
742
+
743
+ // src/runner/recipe-secrets.ts
744
+ var CREDENTIAL_KEYS = /* @__PURE__ */ new Set(["domain", "header", "source", "requests"]);
745
+ var UNSAFE_SECRET_ENV_VAR_KEYS = /* @__PURE__ */ new Set(["name", "source"]);
746
+ var ENV_SOURCE_KEYS = /* @__PURE__ */ new Set(["kind", "name"]);
747
+ var DEFAULT_CREDENTIAL_HEADER = "authorization";
748
+ var HOST_PATTERN = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
749
+ var HEADER_PATTERN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
750
+ var REFUSED_HEADERS = /* @__PURE__ */ new Set(["host", "content-length", "transfer-encoding", "connection"]);
751
+ var RESERVED_UNSAFE_SECRET_ENV_VAR_NAMES = /* @__PURE__ */ new Set([
752
+ "PATH",
753
+ "HOME",
754
+ "USER",
755
+ "LOGNAME",
756
+ "SHELL",
757
+ "PWD",
758
+ "TMPDIR",
759
+ "BASH_ENV",
760
+ "ENV",
761
+ "IFS",
762
+ "NODE_OPTIONS",
763
+ "NO_UPDATE_NOTIFIER",
764
+ "FORCE_COLOR",
765
+ "NO_COLOR"
766
+ ]);
767
+ var RESERVED_UNSAFE_SECRET_ENV_VAR_PREFIXES = ["LD_", "DYLD_"];
768
+ function credentialSourceIds(recipe) {
769
+ return [...new Set(recipe.credentials.map(({ source }) => secretSourceId(source)))].toSorted();
488
770
  }
489
- function splitLines(text) {
490
- if (text === "") return [];
491
- const lines = text.split("\n");
492
- if (lines.at(-1) === "") lines.pop();
493
- return lines;
771
+ function checkCredentials(value, report) {
772
+ if (value === void 0) return [];
773
+ if (!Array.isArray(value)) {
774
+ report(
775
+ ["credentials"],
776
+ `must be a list of credentials, each { domain, header?, source, requests? }, not ${describeRecipeValue(value)}`
777
+ );
778
+ return void 0;
779
+ }
780
+ let ok = true;
781
+ const checked = [];
782
+ const byTarget = /* @__PURE__ */ new Map();
783
+ const byDomain = /* @__PURE__ */ new Map();
784
+ value.forEach((entry, index) => {
785
+ const path = ["credentials", String(index)];
786
+ const credential = checkCredential(entry, path, report);
787
+ if (credential === void 0) {
788
+ ok = false;
789
+ return;
790
+ }
791
+ const target = `${credential.domain} ${credential.header}`;
792
+ const sameTarget = byTarget.get(target);
793
+ const sameDomain = byDomain.get(credential.domain);
794
+ if (sameTarget !== void 0) {
795
+ report(
796
+ path,
797
+ `goes to the same domain and header as runner.credentials.${sameTarget}: ${credential.header} on ${credential.domain}`
798
+ );
799
+ ok = false;
800
+ } else if (sameDomain !== void 0 && sameDomain.requests !== credential.requests) {
801
+ report(
802
+ [...path, "requests"],
803
+ `can't be ${credential.requests}: runner.credentials.${sameDomain.index} goes to ${credential.domain} with ${sameDomain.requests}, and every credential for one domain has the same requests`
804
+ );
805
+ ok = false;
806
+ }
807
+ if (sameTarget === void 0) byTarget.set(target, index);
808
+ if (sameDomain === void 0) byDomain.set(credential.domain, { index, requests: credential.requests });
809
+ checked.push(credential);
810
+ });
811
+ return ok ? checked : void 0;
494
812
  }
495
-
496
- // src/runner/steps.ts
497
- var STEP_ENV = {
498
- HUSKY: "0",
499
- COREPACK_ENABLE_DOWNLOAD_PROMPT: "0",
500
- COREPACK_ENABLE_STRICT: "0",
501
- npm_config_update_notifier: "false"
502
- };
503
- async function runStep(context, request2, progress, signal) {
504
- const { phase, label } = request2;
505
- const startedAt = context.clock.now().getTime();
506
- await progress.emit({ kind: "step-started", phase, label });
507
- const queue = progressQueue(progress);
508
- const tail = outputTail();
509
- const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
510
- const emit = (stream, text) => {
511
- for (const line of splitLines(text)) {
512
- tail.add(line);
513
- queue.add({ kind: "step-output", phase, stream, line });
813
+ function checkCredential(value, path, report) {
814
+ if (!isPlainObject(value)) {
815
+ report(path, `must be { domain, header?, source, requests? }, not ${describeRecipeValue(value)}`);
816
+ return void 0;
817
+ }
818
+ let ok = reportUnknownKeys(value, CREDENTIAL_KEYS, path, "a credential key", report);
819
+ const domain = value["domain"];
820
+ if (typeof domain !== "string" || !HOST_PATTERN.test(domain)) {
821
+ report(
822
+ [...path, "domain"],
823
+ `must be a bare hostname, such as registry.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, path, or wildcard, not ${describeRecipeValue(domain)}`
824
+ );
825
+ ok = false;
826
+ }
827
+ const header = value["header"] === void 0 ? DEFAULT_CREDENTIAL_HEADER : value["header"];
828
+ if (typeof header !== "string" || !HEADER_PATTERN.test(header)) {
829
+ report(
830
+ [...path, "header"],
831
+ `must be an HTTP header name, such as authorization, not ${describeRecipeValue(header)}`
832
+ );
833
+ ok = false;
834
+ } else if (REFUSED_HEADERS.has(header.toLowerCase())) {
835
+ report([...path, "header"], `can't be ${header}: the firewall or HTTP sets it`);
836
+ ok = false;
837
+ }
838
+ const source = checkSecretSource(value["source"], [...path, "source"], report);
839
+ if (source === void 0) ok = false;
840
+ const requests = value["requests"] === void 0 ? "read" : value["requests"];
841
+ if (requests !== "read" && requests !== "all") {
842
+ report([...path, "requests"], `must be "read" or "all", not ${describeRecipeValue(requests)}`);
843
+ ok = false;
844
+ }
845
+ return ok && source !== void 0 ? {
846
+ domain,
847
+ header: header.toLowerCase(),
848
+ source,
849
+ requests
850
+ } : void 0;
851
+ }
852
+ function checkSecretSource(value, path, report) {
853
+ if (!isPlainObject(value)) {
854
+ report(path, `must be a secret source, { kind: "env", name }, not ${describeRecipeValue(value)}`);
855
+ return void 0;
856
+ }
857
+ const kind2 = value["kind"];
858
+ if (kind2 !== "env") {
859
+ report([...path, "kind"], `must be "env", not ${describeRecipeValue(kind2)}`);
860
+ if (kind2 !== void 0) return void 0;
861
+ }
862
+ let ok = kind2 === "env";
863
+ if (!reportUnknownKeys(value, ENV_SOURCE_KEYS, path, "a secret source key", report)) ok = false;
864
+ const name = value["name"];
865
+ if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
866
+ report([...path, "name"], `must be ${ENV_VAR_NAME_RULE}, not ${describeRecipeValue(name)}`);
867
+ ok = false;
868
+ }
869
+ return ok ? { kind: "env", name } : void 0;
870
+ }
871
+ function checkUnsafeSecretEnvVars(value, env, credentials2, report) {
872
+ if (value === void 0) return [];
873
+ if (!Array.isArray(value)) {
874
+ report(
875
+ ["unsafeSecretEnvVars"],
876
+ `must be a list of unsafe secret environment variables, each { name, source }, not ${describeRecipeValue(value)}`
877
+ );
878
+ return void 0;
879
+ }
880
+ let ok = true;
881
+ const checked = [];
882
+ const seen = /* @__PURE__ */ new Set();
883
+ const credentialSources = new Set((credentials2 ?? []).map(({ source }) => secretSourceId(source)));
884
+ value.forEach((entry, index) => {
885
+ const path = ["unsafeSecretEnvVars", String(index)];
886
+ if (!isPlainObject(entry)) {
887
+ report(path, `must be { name, source }, not ${describeRecipeValue(entry)}`);
888
+ ok = false;
889
+ return;
514
890
  }
515
- };
516
- const ran = await context.runnerSandboxes.runScript(
517
- request2.sandbox,
518
- { script: request2.script, env: { ...STEP_ENV, ...request2.secrets } },
519
- ({ stream, data }) => emit(stream, splitters[stream].push(data)),
520
- signal
521
- );
522
- emit("stdout", splitters.stdout.flush());
523
- emit("stderr", splitters.stderr.flush());
524
- await queue.flush();
525
- if (!ran.ok) return { kind: "sandbox-failed", failure: ran.failure };
526
- if (ran.value.exitCode !== 0) return { kind: "exited", exitCode: ran.value.exitCode, tail: tail.lines() };
527
- const ms = context.clock.now().getTime() - startedAt;
528
- await progress.emit({ kind: "step-finished", phase, label, ms });
529
- return { kind: "succeeded", ms };
891
+ let entryOk = reportUnknownKeys(
892
+ entry,
893
+ UNSAFE_SECRET_ENV_VAR_KEYS,
894
+ path,
895
+ "an unsafe secret environment variable key",
896
+ report
897
+ );
898
+ const name = entry["name"];
899
+ const namePath = [...path, "name"];
900
+ if (typeof name !== "string" || !ENV_VAR_NAME_PATTERN.test(name)) {
901
+ report(namePath, `must be ${ENV_VAR_NAME_RULE}, not ${describeRecipeValue(name)}`);
902
+ entryOk = false;
903
+ } else if (name === RUN_PAYLOAD_VARIABLE) {
904
+ report(namePath, `can't be ${name}: storm sets it for the command`);
905
+ entryOk = false;
906
+ } else if (RESERVED_UNSAFE_SECRET_ENV_VAR_NAMES.has(name)) {
907
+ report(namePath, `can't be ${name}: it changes how the command's shell or programs run`);
908
+ entryOk = false;
909
+ } else if (reservedUnsafeSecretEnvVarPrefix(name) !== void 0) {
910
+ report(
911
+ namePath,
912
+ `can't be ${name}: a name starting with ${reservedUnsafeSecretEnvVarPrefix(name)} changes how the command's programs load`
913
+ );
914
+ entryOk = false;
915
+ } else if (env !== void 0 && Object.hasOwn(env, name)) {
916
+ report(namePath, `can't be ${name}: runner.env already sets it`);
917
+ entryOk = false;
918
+ } else if (seen.has(name)) {
919
+ report(namePath, `names ${name} again`);
920
+ entryOk = false;
921
+ }
922
+ if (typeof name === "string") seen.add(name);
923
+ const source = checkSecretSource(entry["source"], [...path, "source"], report);
924
+ if (source === void 0) {
925
+ entryOk = false;
926
+ } else if (credentialSources.has(secretSourceId(source))) {
927
+ report([...path, "source"], `can't use ${secretSourceId(source)}: runner.credentials already reads it`);
928
+ entryOk = false;
929
+ }
930
+ if (entryOk && source !== void 0) checked.push({ name, source });
931
+ else ok = false;
932
+ });
933
+ return ok ? checked : void 0;
530
934
  }
531
- function sandboxApiFailure(operation, failure) {
532
- if (failure.kind === "snapshot-gone")
533
- return { kind: "sandbox-api-failed", operation, status: 410, message: failure.message };
534
- return { kind: "sandbox-api-failed", operation, status: failure.status ?? null, message: failure.message };
935
+ function reservedUnsafeSecretEnvVarPrefix(name) {
936
+ return RESERVED_UNSAFE_SECRET_ENV_VAR_PREFIXES.find((prefix) => name.startsWith(prefix));
535
937
  }
536
- function sandboxStop(operation, failure) {
537
- return failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", failure: sandboxApiFailure(operation, failure) };
938
+ function isPlainObject(value) {
939
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
940
+ const proto = Object.getPrototypeOf(value);
941
+ return proto === Object.prototype || proto === null;
538
942
  }
539
943
 
540
944
  // src/runner/recipe.ts
945
+ var MAX_RUNNER_SANDBOXES = 32;
541
946
  var RECIPE_DEFAULTS = {
542
947
  cwd: ".",
543
948
  timeout: "60m",
@@ -552,32 +957,22 @@ var RECIPE_KEYS = /* @__PURE__ */ new Set([
552
957
  "cwd",
553
958
  "vcpus",
554
959
  "env",
555
- "secrets",
960
+ "credentials",
961
+ "unsafeSecretEnvVars",
962
+ "allowedDomains",
556
963
  "timeout",
557
964
  "keepSandbox",
558
965
  "baseRefs",
559
966
  "region",
560
- "runtime"
967
+ "runtime",
968
+ "sandboxes"
561
969
  ]);
970
+ var SANDBOXES_KEYS = /* @__PURE__ */ new Set(["max", "default"]);
562
971
  var SNAPSHOT_KEYS = /* @__PURE__ */ new Set(["vcpus", "summary", "toolchains", "prebuild"]);
563
972
  var RUN_KEYS = /* @__PURE__ */ new Set(["install", "build"]);
564
- var STEP_KEYS = /* @__PURE__ */ new Set(["label", "script", "secrets"]);
973
+ var STEP_KEYS = /* @__PURE__ */ new Set(["label", "script"]);
565
974
  var NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
566
- var VARIABLE_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
567
- var RESERVED_SECRET_NAMES = /* @__PURE__ */ new Set([
568
- "PATH",
569
- "HOME",
570
- "USER",
571
- "LOGNAME",
572
- "SHELL",
573
- "PWD",
574
- "TMPDIR",
575
- "BASH_ENV",
576
- "ENV",
577
- "IFS",
578
- "NODE_OPTIONS"
579
- ]);
580
- var RESERVED_SECRET_PREFIXES = ["LD_", "DYLD_"];
975
+ var ALLOWED_DOMAIN_PATTERN = /^(?:\*\.)?(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
581
976
  function checkRecipe(value) {
582
977
  const problems = [];
583
978
  const report = (path, problem) => problems.push({ path, problem });
@@ -592,9 +987,8 @@ function checkRecipe(value) {
592
987
  ["name"],
593
988
  `must be lowercase letters, digits and dashes, starting with a letter or digit, not ${describeRecipeValue(name)}`
594
989
  );
595
- const declared = declaredSecrets(value["secrets"]);
596
- const snapshot = checkSnapshot(value["snapshot"], declared, report);
597
- const run = checkRun(value["run"], declared, report);
990
+ const snapshot = checkSnapshot(value["snapshot"], report);
991
+ const run = checkRun(value["run"], report);
598
992
  const cwd = orDefault(value["cwd"], RECIPE_DEFAULTS.cwd);
599
993
  if (!isRelativePath(cwd))
600
994
  report(["cwd"], `must be a path relative to the repository's root, without "..", not ${describeRecipeValue(cwd)}`);
@@ -602,7 +996,9 @@ function checkRecipe(value) {
602
996
  if (typeof vcpus !== "function" && !isPositiveInteger(vcpus))
603
997
  report(["vcpus"], `must be a positive whole number, or a function of the run, not ${describeRecipeValue(vcpus)}`);
604
998
  const env = checkEnv(value["env"], report);
605
- const secrets = checkSecrets(value["secrets"], report);
999
+ const credentials2 = checkCredentials(value["credentials"], report);
1000
+ const unsafeSecretEnvVars = checkUnsafeSecretEnvVars(value["unsafeSecretEnvVars"], env, credentials2, report);
1001
+ const allowedDomains = checkAllowedDomains(value["allowedDomains"], report);
606
1002
  const timeout = orDefault(value["timeout"], RECIPE_DEFAULTS.timeout);
607
1003
  const timeoutMinutes = typeof timeout === "string" ? parseTtl(timeout) : void 0;
608
1004
  if (timeoutMinutes === void 0)
@@ -617,13 +1013,19 @@ function checkRecipe(value) {
617
1013
  ["keepSandbox"],
618
1014
  `must be 0, or a whole number of minutes or hours up to 5h, not ${describeRecipeValue(keepSandbox)}`
619
1015
  );
1016
+ else if (unsafeSecretEnvVars !== void 0 && unsafeSecretEnvVars.length > 0 && keepSandboxMinutes !== void 0 && keepSandboxMinutes > 0)
1017
+ report(
1018
+ ["keepSandbox"],
1019
+ "can't be above 0 when runner.unsafeSecretEnvVars is set: a run that passes secrets into the runner sandbox's environment never keeps its runner sandbox"
1020
+ );
620
1021
  const baseRefs = checkBaseRefs(value["baseRefs"], report);
621
1022
  const region = orDefault(value["region"], RECIPE_DEFAULTS.region);
622
1023
  if (!isNonEmptyString(region)) report(["region"], `must be a non-empty string, not ${describeRecipeValue(region)}`);
623
1024
  const runtime = orDefault(value["runtime"], RECIPE_DEFAULTS.runtime);
624
1025
  if (!isNonEmptyString(runtime))
625
1026
  report(["runtime"], `must be a non-empty string, not ${describeRecipeValue(runtime)}`);
626
- if (problems.length > 0 || snapshot === void 0 || run === void 0 || env === void 0 || secrets === void 0 || baseRefs === void 0 || timeoutMinutes === void 0)
1027
+ const sandboxes = checkSandboxes(value["sandboxes"], report);
1028
+ if (problems.length > 0 || snapshot === void 0 || run === void 0 || env === void 0 || credentials2 === void 0 || unsafeSecretEnvVars === void 0 || allowedDomains === null || baseRefs === void 0 || timeoutMinutes === void 0 || sandboxes === false)
627
1029
  return { ok: false, problems };
628
1030
  return {
629
1031
  ok: true,
@@ -634,22 +1036,49 @@ function checkRecipe(value) {
634
1036
  cwd,
635
1037
  vcpus,
636
1038
  env,
637
- secrets,
1039
+ credentials: credentials2,
1040
+ unsafeSecretEnvVars,
1041
+ ...allowedDomains === void 0 ? {} : { allowedDomains },
638
1042
  timeout,
639
1043
  timeoutMinutes,
640
1044
  keepSandboxMinutes,
641
1045
  baseRefs,
642
1046
  region,
643
- runtime
1047
+ runtime,
1048
+ ...sandboxes === void 0 ? {} : { sandboxes }
644
1049
  }
645
1050
  };
646
1051
  }
647
- function declaredSecrets(value) {
648
- if (value === void 0) return /* @__PURE__ */ new Set();
649
- if (!Array.isArray(value)) return void 0;
650
- return new Set(value.filter((name) => typeof name === "string"));
1052
+ function checkSandboxes(value, report) {
1053
+ if (value === void 0) return void 0;
1054
+ if (!isRecord(value)) {
1055
+ report(["sandboxes"], `must be an object with max, not ${describeRecipeValue(value)}`);
1056
+ return false;
1057
+ }
1058
+ let ok = reportUnknownKeys(value, SANDBOXES_KEYS, ["sandboxes"], "a runner recipe sandboxes key", report);
1059
+ const max = value["max"];
1060
+ if (!isPositiveInteger(max) || max > MAX_RUNNER_SANDBOXES) {
1061
+ report(
1062
+ ["sandboxes", "max"],
1063
+ `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, not ${describeRecipeValue(max)}`
1064
+ );
1065
+ ok = false;
1066
+ }
1067
+ const sandboxesDefault = value["default"];
1068
+ if (sandboxesDefault !== void 0 && typeof sandboxesDefault !== "function" && !(isPositiveInteger(sandboxesDefault) && sandboxesDefault <= MAX_RUNNER_SANDBOXES)) {
1069
+ report(
1070
+ ["sandboxes", "default"],
1071
+ `must be a whole number from 1 to ${MAX_RUNNER_SANDBOXES}, or a function of the run's test plan, not ${describeRecipeValue(sandboxesDefault)}`
1072
+ );
1073
+ ok = false;
1074
+ }
1075
+ if (!ok) return false;
1076
+ return {
1077
+ max,
1078
+ ...sandboxesDefault === void 0 ? {} : { default: sandboxesDefault }
1079
+ };
651
1080
  }
652
- function checkSnapshot(value, declared, report) {
1081
+ function checkSnapshot(value, report) {
653
1082
  if (!isRecord(value)) {
654
1083
  report(
655
1084
  ["snapshot"],
@@ -668,8 +1097,8 @@ function checkSnapshot(value, declared, report) {
668
1097
  report(["snapshot", "summary"], `must be a non-empty string, not ${describeRecipeValue(summary)}`);
669
1098
  ok = false;
670
1099
  }
671
- const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], declared, report);
672
- const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], declared, report);
1100
+ const toolchains = checkSteps(value["toolchains"], ["snapshot", "toolchains"], report);
1101
+ const prebuild = checkSteps(value["prebuild"], ["snapshot", "prebuild"], report);
673
1102
  if (!ok || toolchains === void 0 || prebuild === void 0) return void 0;
674
1103
  return {
675
1104
  vcpus,
@@ -678,31 +1107,39 @@ function checkSnapshot(value, declared, report) {
678
1107
  prebuild
679
1108
  };
680
1109
  }
681
- function checkRun(value, declared, report) {
1110
+ function checkRun(value, report) {
682
1111
  if (!isRecord(value)) {
683
1112
  report(["run"], `must be an object of install and build steps, not ${describeRecipeValue(value)}`);
684
1113
  return void 0;
685
1114
  }
686
1115
  const ok = reportUnknownKeys(value, RUN_KEYS, ["run"], "a runner recipe run key", report);
687
- const install = checkStep(value["install"], ["run", "install"], declared, report);
688
- const build = checkStep(value["build"], ["run", "build"], declared, report);
1116
+ const install = checkStep(value["install"], ["run", "install"], report);
1117
+ const build = checkStep(value["build"], ["run", "build"], report);
689
1118
  return ok && install !== void 0 && build !== void 0 ? { install, build } : void 0;
690
1119
  }
691
- function checkSteps(value, path, declared, report) {
1120
+ function checkSteps(value, path, report) {
692
1121
  if (typeof value === "function") return value;
693
1122
  if (!Array.isArray(value)) {
694
1123
  report(path, `must be a list of steps, or a function that returns one, not ${describeRecipeValue(value)}`);
695
1124
  return void 0;
696
1125
  }
697
- const steps = value.map((step, index) => checkStep(step, [...path, String(index)], declared, report));
1126
+ const steps = value.map((step, index) => checkStep(step, [...path, String(index)], report));
698
1127
  return steps.every((step) => step !== void 0) ? steps : void 0;
699
1128
  }
700
- function checkStep(value, path, declared, report) {
1129
+ function checkStep(value, path, report) {
701
1130
  if (!isRecord(value)) {
702
1131
  report(path, `must be a step, { label, script }, not ${describeRecipeValue(value)}`);
703
1132
  return void 0;
704
1133
  }
705
- let ok = reportUnknownKeys(value, STEP_KEYS, path, "a step key", report);
1134
+ let ok = true;
1135
+ for (const key of Object.keys(value)) {
1136
+ if (STEP_KEYS.has(key)) continue;
1137
+ report(
1138
+ [...path, key],
1139
+ key === "secrets" ? "is not a step key: every recipe step gets every credential runner.credentials declares" : "is not a step key"
1140
+ );
1141
+ ok = false;
1142
+ }
706
1143
  const label = value["label"];
707
1144
  const script = value["script"];
708
1145
  if (!isNonEmptyString(label)) {
@@ -713,33 +1150,7 @@ function checkStep(value, path, declared, report) {
713
1150
  report([...path, "script"], `must be a non-empty string, not ${describeRecipeValue(script)}`);
714
1151
  ok = false;
715
1152
  }
716
- const secrets = checkStepSecrets(value["secrets"], [...path, "secrets"], declared, report);
717
- if (secrets === void 0) ok = false;
718
- return ok && secrets !== void 0 ? { label, script, secrets } : void 0;
719
- }
720
- function checkStepSecrets(value, path, declared, report) {
721
- if (value === void 0) return [];
722
- if (!Array.isArray(value)) {
723
- report(path, `must be a list of names runner.secrets declares, not ${describeRecipeValue(value)}`);
724
- return void 0;
725
- }
726
- let ok = true;
727
- const seen = /* @__PURE__ */ new Set();
728
- value.forEach((name, index) => {
729
- const at = [...path, String(index)];
730
- if (typeof name !== "string") {
731
- report(at, `must be a name runner.secrets declares, not ${describeRecipeValue(name)}`);
732
- ok = false;
733
- } else if (declared !== void 0 && !declared.has(name)) {
734
- report(at, `names ${name}, which runner.secrets doesn't declare`);
735
- ok = false;
736
- } else if (seen.has(name)) {
737
- report(at, `names ${name} again`);
738
- ok = false;
739
- }
740
- if (typeof name === "string") seen.add(name);
741
- });
742
- return ok ? [...value] : void 0;
1153
+ return ok ? { label, script } : void 0;
743
1154
  }
744
1155
  function checkEnv(value, report) {
745
1156
  if (value === void 0) return {};
@@ -760,44 +1171,39 @@ function checkEnv(value, report) {
760
1171
  }
761
1172
  return ok ? env : void 0;
762
1173
  }
763
- function checkSecrets(value, report) {
764
- if (value === void 0) return [];
1174
+ function checkAllowedDomains(value, report) {
1175
+ if (value === void 0) return void 0;
765
1176
  if (!Array.isArray(value)) {
766
- report(["secrets"], `must be a list of environment variable names, not ${describeRecipeValue(value)}`);
767
- return void 0;
1177
+ report(
1178
+ ["allowedDomains"],
1179
+ `must be a list of domains, such as ["registry.npmjs.org", "*.example.com"], not ${describeRecipeValue(value)}`
1180
+ );
1181
+ return null;
1182
+ }
1183
+ if (value.length === 0) {
1184
+ report(["allowedDomains"], "must list at least one domain: leave the key out for full access");
1185
+ return null;
768
1186
  }
769
1187
  let ok = true;
770
1188
  const seen = /* @__PURE__ */ new Set();
771
- value.forEach((name, index) => {
772
- const path = ["secrets", String(index)];
773
- if (typeof name !== "string" || !VARIABLE_PATTERN.test(name)) {
1189
+ value.forEach((domain, index) => {
1190
+ const at = ["allowedDomains", String(index)];
1191
+ if (domain === "*") {
1192
+ report(at, "can't be *, which would allow every domain: leave runner.allowedDomains out for full access");
1193
+ ok = false;
1194
+ } else if (typeof domain !== "string" || !ALLOWED_DOMAIN_PATTERN.test(domain)) {
774
1195
  report(
775
- path,
776
- `must be an environment variable name, letters, digits and underscores, not starting with a digit, not ${describeRecipeValue(name)}`
1196
+ at,
1197
+ `must be a hostname, such as example.com, or a wildcard with one leading *., such as *.example.com: lowercase letters, digits, dots, and hyphens, with at least one dot, and no scheme, port, or path, not ${describeRecipeValue(domain)}`
777
1198
  );
778
1199
  ok = false;
779
- } else if (name === RUN_PAYLOAD_VARIABLE) {
780
- report(path, `can't be ${name}: storm sets it for the command`);
781
- ok = false;
782
- } else if (Object.hasOwn(STEP_ENV, name)) {
783
- report(path, `can't be ${name}: storm sets it for every step`);
784
- ok = false;
785
- } else if (RESERVED_SECRET_NAMES.has(name)) {
786
- report(path, `can't be ${name}: it changes how a step's shell or programs run`);
787
- ok = false;
788
- } else if (reservedPrefix(name) !== void 0) {
789
- report(path, `can't be ${name}: a name starting with ${reservedPrefix(name)} changes how a step's programs load`);
790
- ok = false;
791
- } else if (seen.has(name)) {
792
- report(path, `names ${name} again`);
1200
+ } else if (seen.has(domain)) {
1201
+ report(at, `lists ${domain} again`);
793
1202
  ok = false;
794
1203
  }
795
- if (typeof name === "string") seen.add(name);
1204
+ if (typeof domain === "string") seen.add(domain);
796
1205
  });
797
- return ok ? [...value] : void 0;
798
- }
799
- function reservedPrefix(name) {
800
- return RESERVED_SECRET_PREFIXES.find((prefix) => name.startsWith(prefix));
1206
+ return ok ? [...value] : null;
801
1207
  }
802
1208
  function checkBaseRefs(value, report) {
803
1209
  if (value === void 0) return [...RECIPE_DEFAULTS.baseRefs];
@@ -814,21 +1220,8 @@ function checkBaseRefs(value, report) {
814
1220
  });
815
1221
  return ok ? [...value] : void 0;
816
1222
  }
817
- function reportUnknownKeys(value, known, path, what, report) {
818
- let ok = true;
819
- for (const key of Object.keys(value))
820
- if (!known.has(key)) {
821
- report([...path, key], `is not ${what}`);
822
- ok = false;
823
- }
824
- return ok;
825
- }
826
- async function resolveSteps(steps, context, declared) {
827
- if (typeof steps !== "function")
828
- return {
829
- ok: true,
830
- steps: steps.map(({ label, script, secrets }) => ({ label, script, secrets: [...secrets ?? []] }))
831
- };
1223
+ async function resolveSteps(steps, context) {
1224
+ if (typeof steps !== "function") return { ok: true, steps: steps.map(({ label, script }) => ({ label, script })) };
832
1225
  let returned;
833
1226
  try {
834
1227
  returned = await steps(context);
@@ -838,9 +1231,8 @@ async function resolveSteps(steps, context, declared) {
838
1231
  if (!Array.isArray(returned))
839
1232
  return { ok: false, problem: `must return a list of steps, not ${describeRecipeValue(returned)}` };
840
1233
  const problems = [];
841
- const names = new Set(declared);
842
1234
  const checked = returned.map(
843
- (step, index) => checkStep(step, [String(index)], names, (path, problem) => problems.push({ path, problem }))
1235
+ (step, index) => checkStep(step, [String(index)], (path, problem) => problems.push({ path, problem }))
844
1236
  );
845
1237
  const first = problems[0];
846
1238
  if (first !== void 0)
@@ -863,21 +1255,29 @@ function resolveVcpus(recipe, { run, resourceKeys }) {
863
1255
  problem: `must return a positive whole number, not ${describeRecipeValue(returned)} for ${describeResourceKeys(resourceKeys)}`
864
1256
  };
865
1257
  }
1258
+ function resolveSandboxCountDefault(sandboxesDefault, testPlan) {
1259
+ if (typeof sandboxesDefault !== "function") return { ok: true, sandboxes: sandboxesDefault };
1260
+ let returned;
1261
+ try {
1262
+ returned = sandboxesDefault(Object.freeze({ testPlan }));
1263
+ } catch (error) {
1264
+ return { ok: false, problem: `threw for ${describeTestPlan(testPlan)}: ${errorMessage(error)}` };
1265
+ }
1266
+ return isPositiveInteger(returned) ? { ok: true, sandboxes: returned } : {
1267
+ ok: false,
1268
+ problem: `must return a whole number from 1, not ${describeRecipeValue(returned)} for ${describeTestPlan(testPlan)}`
1269
+ };
1270
+ }
1271
+ function describeTestPlan(testPlan) {
1272
+ if (testPlan.kind !== "counted") return "a test plan that counted nothing";
1273
+ const files = `${testPlan.files} test ${testPlan.files === 1 ? "file" : "files"}`;
1274
+ return testPlan.tests === void 0 ? `a test plan of ${files}` : `a test plan of ${testPlan.tests} ${testPlan.tests === 1 ? "test" : "tests"} in ${files}`;
1275
+ }
866
1276
  function describeResourceKeys(names) {
867
1277
  const last = names.at(-1);
868
1278
  if (last === void 0) return "a run with no resource";
869
1279
  return `a run with ${names.length === 1 ? last : `${names.slice(0, -1).join(", ")} and ${last}`}`;
870
1280
  }
871
- function describeRecipeValue(value) {
872
- if (typeof value === "string") return JSON.stringify(value);
873
- if (typeof value === "number" || typeof value === "boolean") return String(value);
874
- if (value === null) return "null";
875
- if (value === void 0) return "undefined";
876
- if (typeof value === "function") return "a function";
877
- if (Array.isArray(value)) return value.length === 0 ? "an empty array" : "an array";
878
- if (typeof value === "object") return "an object";
879
- return `a ${typeof value}`;
880
- }
881
1281
  function errorMessage(error) {
882
1282
  return error instanceof Error ? error.message : String(error);
883
1283
  }
@@ -898,7 +1298,7 @@ function isRelativePath(value) {
898
1298
  }
899
1299
 
900
1300
  // src/runner/snapshot-key.ts
901
- var SNAPSHOT_FORMAT = 3;
1301
+ var SNAPSHOT_FORMAT = 4;
902
1302
  var SANDBOX_ROOT = "/vercel/sandbox";
903
1303
  var STAGED_FILES = {
904
1304
  baseTarball: "base.tgz",
@@ -946,10 +1346,11 @@ function applyScript(staging, root = SANDBOX_ROOT) {
946
1346
  );
947
1347
  }
948
1348
  function snapshotKey(steps) {
949
- const text = (list) => list.flatMap(({ label, script, secrets }) => [label, script, `secrets=${(secrets ?? []).toSorted().join(",")}`]);
1349
+ const text = (list) => list.flatMap(({ label, script }) => [label, script]);
950
1350
  return createHash2("sha256").update(
951
1351
  [
952
1352
  `format=${SNAPSHOT_FORMAT}`,
1353
+ `credentials=${[...new Set(steps.credentials)].toSorted().join(",")}`,
953
1354
  ...text(steps.toolchains),
954
1355
  baseIndexScript("<base>", "<staging>"),
955
1356
  ...text(steps.prebuild)
@@ -958,18 +1359,142 @@ function snapshotKey(steps) {
958
1359
  }
959
1360
  async function snapshotStepsAt(checkout, request2) {
960
1361
  const context = baseStepContext(checkout, request2);
961
- const { snapshot, secrets } = request2.recipe;
962
- const toolchains = await resolveSteps(snapshot.toolchains, context, secrets);
1362
+ const { snapshot } = request2.recipe;
1363
+ const toolchains = await resolveSteps(snapshot.toolchains, context);
963
1364
  if (!toolchains.ok) return { ok: false, path: ["snapshot", "toolchains"], problem: toolchains.problem };
964
- const prebuild = await resolveSteps(snapshot.prebuild, context, secrets);
1365
+ const prebuild = await resolveSteps(snapshot.prebuild, context);
965
1366
  if (!prebuild.ok) return { ok: false, path: ["snapshot", "prebuild"], problem: prebuild.problem };
966
1367
  return {
967
1368
  ok: true,
968
1369
  toolchains: toolchains.steps,
969
1370
  prebuild: prebuild.steps,
970
- key: snapshotKey({ toolchains: toolchains.steps, prebuild: prebuild.steps })
1371
+ key: snapshotKey({
1372
+ credentials: credentialSourceIds(request2.recipe),
1373
+ toolchains: toolchains.steps,
1374
+ prebuild: prebuild.steps
1375
+ })
1376
+ };
1377
+ }
1378
+
1379
+ // src/runner/events.ts
1380
+ function progressQueue(progress) {
1381
+ let pending = Promise.resolve();
1382
+ return {
1383
+ add(event) {
1384
+ pending = pending.then(() => progress.emit(event));
1385
+ },
1386
+ flush: () => pending
1387
+ };
1388
+ }
1389
+
1390
+ // src/runner/output.ts
1391
+ var OUTPUT_TAIL_LINES = 40;
1392
+ function lineSplitter() {
1393
+ let buffer = "";
1394
+ return {
1395
+ push(chunk) {
1396
+ const end = chunk.lastIndexOf("\n");
1397
+ if (end === -1) {
1398
+ buffer += chunk;
1399
+ return "";
1400
+ }
1401
+ const lines = buffer + chunk.slice(0, end + 1);
1402
+ buffer = chunk.slice(end + 1);
1403
+ return lines;
1404
+ },
1405
+ flush() {
1406
+ const rest = buffer;
1407
+ buffer = "";
1408
+ return rest;
1409
+ }
1410
+ };
1411
+ }
1412
+ function rewritePaths(text, fromRoot, toRoot) {
1413
+ const from = `${fromRoot.replace(/\/+$/, "")}/`;
1414
+ const to = `${toRoot.replace(/\/+$/, "")}/`;
1415
+ return text.split(from).join(to);
1416
+ }
1417
+ function outputTail(limit = OUTPUT_TAIL_LINES) {
1418
+ const kept = [];
1419
+ return {
1420
+ add(line) {
1421
+ kept.push(line);
1422
+ if (kept.length > limit) kept.shift();
1423
+ },
1424
+ lines: () => [...kept]
1425
+ };
1426
+ }
1427
+ function splitLines(text) {
1428
+ if (text === "") return [];
1429
+ const lines = text.split("\n");
1430
+ if (lines.at(-1) === "") lines.pop();
1431
+ return lines;
1432
+ }
1433
+
1434
+ // src/runner/steps.ts
1435
+ var STEP_ENV = {
1436
+ HUSKY: "0",
1437
+ COREPACK_ENABLE_DOWNLOAD_PROMPT: "0",
1438
+ COREPACK_ENABLE_STRICT: "0",
1439
+ npm_config_update_notifier: "false"
1440
+ };
1441
+ async function runStep(context, request2, progress, signal) {
1442
+ const { phase, label } = request2;
1443
+ const startedAt = context.clock.now().getTime();
1444
+ await progress.emit({ kind: "step-started", phase, label });
1445
+ const queue = progressQueue(progress);
1446
+ const tail = outputTail();
1447
+ const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
1448
+ const emit = (stream, text) => {
1449
+ for (const line of splitLines(text)) {
1450
+ tail.add(line);
1451
+ queue.add({ kind: "step-output", phase, stream, line });
1452
+ }
1453
+ };
1454
+ const ran = await context.runnerSandboxes.runScript(
1455
+ request2.sandbox,
1456
+ { script: request2.script, env: { ...STEP_ENV } },
1457
+ ({ stream, data }) => emit(stream, splitters[stream].push(data)),
1458
+ signal
1459
+ );
1460
+ emit("stdout", splitters.stdout.flush());
1461
+ emit("stderr", splitters.stderr.flush());
1462
+ await queue.flush();
1463
+ if (!ran.ok) return { kind: "sandbox-failed", failure: ran.failure };
1464
+ if (ran.value.exitCode !== 0) return { kind: "exited", exitCode: ran.value.exitCode, tail: tail.lines() };
1465
+ const ms = context.clock.now().getTime() - startedAt;
1466
+ await progress.emit({ kind: "step-finished", phase, label, ms });
1467
+ return { kind: "succeeded", ms };
1468
+ }
1469
+ function networkPolicyStop(operation, around, failure) {
1470
+ if (failure.kind === "aborted") return { kind: "aborted" };
1471
+ return {
1472
+ kind: "failed",
1473
+ failure: failure.kind === "timed-out" ? {
1474
+ kind: "network-policy-failed",
1475
+ operation,
1476
+ around,
1477
+ reason: "timed-out",
1478
+ status: null,
1479
+ message: `no answer within ${failure.limitMs / 1e3} seconds`
1480
+ } : {
1481
+ kind: "network-policy-failed",
1482
+ operation,
1483
+ around,
1484
+ reason: "api",
1485
+ status: failure.status ?? null,
1486
+ message: failure.message
1487
+ }
971
1488
  };
972
1489
  }
1490
+ function sandboxApiFailure(operation, failure) {
1491
+ if (failure.kind === "snapshot-gone")
1492
+ return { kind: "sandbox-api-failed", operation, status: 410, message: failure.message };
1493
+ return { kind: "sandbox-api-failed", operation, status: failure.status ?? null, message: failure.message };
1494
+ }
1495
+ function sandboxStop(operation, failure) {
1496
+ return failure.kind === "aborted" ? { kind: "aborted" } : { kind: "failed", failure: sandboxApiFailure(operation, failure) };
1497
+ }
973
1498
 
974
1499
  // src/runner/snapshot-build.ts
975
1500
  var BUILD_SANDBOX_TIMEOUT_MS = 30 * 6e4;
@@ -1016,36 +1541,48 @@ async function buildSnapshot(context, request2, control, progress) {
1016
1541
  signal
1017
1542
  );
1018
1543
  if (!staged.ok) return sandboxStop("upload", staged.failure);
1019
- const recipeStep = ({ label, script, secrets }) => ({
1020
- label,
1021
- script,
1022
- secrets: stepSecrets(request2.secrets, secrets)
1023
- });
1024
1544
  const steps = [
1025
- ...prepared.toolchains.map(recipeStep),
1545
+ ...prepared.toolchains,
1026
1546
  { label: BASE_INDEX_LABEL, script: baseIndexScript(base, staged.value.directory) },
1027
- ...prepared.prebuild.map(recipeStep)
1547
+ ...prepared.prebuild
1028
1548
  ];
1029
1549
  await progress.emit({ kind: "output-started", section: "snapshot", sandbox: sandbox.name, region: recipe.region });
1030
- for (const step of steps) {
1031
- const ran = await runStep(context, { sandbox, phase: "snapshot", ...step }, progress, signal);
1032
- if (ran.kind === "succeeded") continue;
1033
- const stop = ran.kind === "exited" ? {
1034
- kind: "failed",
1035
- failure: { kind: "snapshot-build-step-failed", label: step.label, exitCode: ran.exitCode, tail: ran.tail }
1036
- } : sandboxStop("run-script", ran.failure);
1037
- await progress.emit({
1038
- kind: "output-ended",
1039
- section: "snapshot",
1040
- outcome: stop.kind === "aborted" ? "stopped" : "failed"
1041
- });
1042
- return stop;
1550
+ let stop;
1551
+ if (request2.credentials.length > 0) {
1552
+ const granted = await scope.grantCredentials(sandbox, request2.credentials, signal);
1553
+ if (!granted.ok) stop = networkPolicyStop("inject", "snapshot-steps", granted.failure);
1554
+ }
1555
+ if (stop === void 0) {
1556
+ for (const step of steps) {
1557
+ if (signal.aborted) {
1558
+ stop = { kind: "aborted" };
1559
+ break;
1560
+ }
1561
+ const ran = await runStep(context, { sandbox, phase: "snapshot", ...step }, progress, signal);
1562
+ if (ran.kind === "succeeded") continue;
1563
+ stop = ran.kind === "exited" ? {
1564
+ kind: "failed",
1565
+ failure: {
1566
+ kind: "snapshot-build-step-failed",
1567
+ label: step.label,
1568
+ exitCode: ran.exitCode,
1569
+ tail: ran.tail
1570
+ }
1571
+ } : sandboxStop("run-script", ran.failure);
1572
+ break;
1573
+ }
1043
1574
  }
1044
- await progress.emit({ kind: "output-ended", section: "snapshot", outcome: "finished" });
1575
+ await progress.emit({
1576
+ kind: "output-ended",
1577
+ section: "snapshot",
1578
+ outcome: stop === void 0 ? "finished" : stop.kind === "aborted" ? "stopped" : "failed"
1579
+ });
1580
+ if (stop !== void 0) return stop;
1045
1581
  if (signal.aborted) return { kind: "aborted" };
1046
1582
  await progress.emit({ kind: "snapshot-saving" });
1047
1583
  const saved = await scope.saveSnapshot(sandbox, { expirationMs: SNAPSHOT_EXPIRATION_MS });
1048
- if (!saved.ok) return sandboxStop("save-snapshot", saved.failure);
1584
+ if (!saved.ok)
1585
+ return saved.failure.kind === "credential-not-revoked" ? networkPolicyStop("remove", "snapshot-save", saved.failure.failure) : sandboxStop("save-snapshot", saved.failure);
1049
1586
  const savedAt = context.clock.now();
1050
1587
  const entry = {
1051
1588
  teamId: access.teamId,
@@ -1138,25 +1675,21 @@ async function prepareSnapshotBuild(context, request2) {
1138
1675
  }
1139
1676
  async function buildSnapshots(context, request2, control, progress) {
1140
1677
  const { signal } = control;
1141
- const scope = runnerSandboxScope(context, progress, { keepMs: 0 });
1142
- const stop = () => {
1143
- void progress.emit({ kind: "stopping", commandRunning: false, keepMs: 0 }).catch(() => void 0);
1144
- void scope.close().catch(() => void 0);
1145
- };
1146
- if (signal.aborted) stop();
1147
- else signal.addEventListener("abort", stop, { once: true });
1678
+ const scope = runnerSandboxScope(context, progress, {
1679
+ keepMs: 0,
1680
+ basePolicy: runnerNetworkPolicy(request2.build.plan.recipe),
1681
+ signal
1682
+ });
1148
1683
  try {
1149
1684
  const ended = await buildIn(context, request2, { scope, signal }, progress);
1150
- signal.removeEventListener("abort", stop);
1151
1685
  return { ...ended, cleanup: await scope.close() };
1152
1686
  } catch (error) {
1153
- signal.removeEventListener("abort", stop);
1154
1687
  await scope.close();
1155
1688
  throw error;
1156
1689
  }
1157
1690
  }
1158
1691
  async function buildIn(context, request2, control, progress) {
1159
- const { build, access, user, secrets } = request2;
1692
+ const { build, access, user, credentials: credentials2 } = request2;
1160
1693
  const { signal } = control;
1161
1694
  if (signal.aborted) return { kind: "aborted", snapshot: null };
1162
1695
  const cached = build.cached.find((entry2) => entry2.teamId === access.teamId && entry2.projectId === access.projectId);
@@ -1168,7 +1701,7 @@ async function buildIn(context, request2, control, progress) {
1168
1701
  prepared: build.plan,
1169
1702
  access,
1170
1703
  user,
1171
- secrets,
1704
+ credentials: credentials2,
1172
1705
  why: why === "no-snapshot" ? { kind: why, rejected: [] } : { kind: why }
1173
1706
  },
1174
1707
  control,
@@ -1191,6 +1724,50 @@ function localUserName() {
1191
1724
  }
1192
1725
  }
1193
1726
 
1727
+ // src/runner/secrets.ts
1728
+ function declaredSecretValues(recipe, env) {
1729
+ if (recipe === void 0) return [];
1730
+ const seen = /* @__PURE__ */ new Set();
1731
+ const values = [];
1732
+ for (const { source } of [...recipe.credentials, ...recipe.unsafeSecretEnvVars]) {
1733
+ const id = secretSourceId(source);
1734
+ if (seen.has(id)) continue;
1735
+ seen.add(id);
1736
+ const value = readSecretSourceValue(source, env);
1737
+ if (value !== void 0) values.push(value);
1738
+ }
1739
+ return values;
1740
+ }
1741
+ function readCredentials(recipe, env) {
1742
+ const read = readUniqueSources(recipe.credentials, env, ({ domain, header, requests }, value) => ({
1743
+ domain,
1744
+ header,
1745
+ value,
1746
+ requests
1747
+ }));
1748
+ return read.ok ? { ok: true, credentials: read.items } : read;
1749
+ }
1750
+ function readUnsafeSecretEnvVars(recipe, env) {
1751
+ const read = readUniqueSources(recipe.unsafeSecretEnvVars, env, ({ name }, value) => [name, value]);
1752
+ return read.ok ? { ok: true, values: Object.fromEntries(read.items) } : read;
1753
+ }
1754
+ function readUniqueSources(entries, env, map) {
1755
+ const cache = /* @__PURE__ */ new Map();
1756
+ const variables = [];
1757
+ const items = [];
1758
+ for (const entry of entries) {
1759
+ const id = secretSourceId(entry.source);
1760
+ let read = cache.get(id);
1761
+ if (read === void 0) {
1762
+ read = readSecretSource(entry.source, env);
1763
+ cache.set(id, read);
1764
+ if (!read.ok) variables.push({ name: describeSecretSource(entry.source), problem: read.problem });
1765
+ }
1766
+ if (read.ok) items.push(map(entry, read.value));
1767
+ }
1768
+ return variables.length === 0 ? { ok: true, items } : { ok: false, variables };
1769
+ }
1770
+
1194
1771
  // src/runner/snapshot-inspect.ts
1195
1772
  async function inspectSnapshotCache(context, request2) {
1196
1773
  const { checkout, runnerSnapshots } = context;
@@ -1552,6 +2129,13 @@ var TERMINATE_GRACE_MS = 1e4;
1552
2129
  var KILL_GRACE_MS = 5e3;
1553
2130
  var STDERR_MESSAGE_CHARS = 1e3;
1554
2131
  var SNAPSHOT_GONE_STATUS = 410;
2132
+ var DROP_CAPABILITIES_ARGS = [
2133
+ "--inh-caps=-all",
2134
+ "--ambient-caps=-all",
2135
+ "--bounding-set=-all",
2136
+ "--no-new-privs",
2137
+ "--"
2138
+ ];
1555
2139
  function liveRunnerSandboxGateway() {
1556
2140
  let loading;
1557
2141
  const sdk = () => loading ??= import("@vercel/sandbox");
@@ -1648,14 +2232,21 @@ function liveRunnerSandboxGateway() {
1648
2232
  const holder = holding(sandbox);
1649
2233
  if (kill.aborted) return { ok: false, failure: { kind: "aborted" } };
1650
2234
  try {
1651
- const cmd = await resolveExecutable(holder, request2);
1652
- if (kill.aborted) return { ok: false, failure: { kind: "aborted" } };
1653
- const command = await startDetached(holder, {
1654
- cmd,
1655
- args: [...request2.args],
2235
+ const cmd = await untilAborted(resolveExecutable(holder, request2, kill), kill);
2236
+ if (cmd === ABORTED || kill.aborted) return { ok: false, failure: { kind: "aborted" } };
2237
+ const starting = startDetached(holder, {
2238
+ cmd: "setpriv",
2239
+ args: [...DROP_CAPABILITIES_ARGS, cmd, ...request2.args],
1656
2240
  cwd: request2.cwd,
1657
2241
  env: { ...request2.env }
1658
2242
  });
2243
+ const command = await untilAborted(starting, kill);
2244
+ if (command === ABORTED) {
2245
+ starting.then((late) => late?.kill("SIGTERM").catch(() => {
2246
+ })).catch(() => {
2247
+ });
2248
+ return { ok: false, failure: { kind: "aborted" } };
2249
+ }
1659
2250
  if (command === void 0) return { ok: false, failure: { kind: "aborted" } };
1660
2251
  const terminate = () => {
1661
2252
  command.kill("SIGTERM").catch(() => {
@@ -1752,6 +2343,19 @@ function liveRunnerSandboxGateway() {
1752
2343
  return { ok: false, failure: sandboxFailure(error, signal) };
1753
2344
  }
1754
2345
  },
2346
+ async writeNetworkPolicy(sandbox, policy, signal) {
2347
+ const holder = holding(sandbox);
2348
+ if (signal?.aborted === true) return { ok: false, failure: { kind: "aborted" } };
2349
+ const networkPolicy = sdkNetworkPolicy(policy);
2350
+ try {
2351
+ await holder.sandbox.update({ networkPolicy }, signal === void 0 ? void 0 : { signal });
2352
+ return { ok: true };
2353
+ } catch (error) {
2354
+ const failure = sandboxFailure(error, signal);
2355
+ if (failure.kind !== "api") return { ok: false, failure };
2356
+ return { ok: false, failure: { ...failure, message: hideCredentialValues(failure.message, policy) } };
2357
+ }
2358
+ },
1755
2359
  async saveSnapshot(sandbox, request2) {
1756
2360
  const holder = holding(sandbox);
1757
2361
  try {
@@ -1777,11 +2381,12 @@ function liveRunnerSandboxGateway() {
1777
2381
  return { ok: false, failure: sandboxFailure(error, void 0) };
1778
2382
  }
1779
2383
  },
1780
- async keepRunning(sandbox, request2) {
2384
+ async keepRunning(sandbox, request2, signal) {
1781
2385
  const holder = holding(sandbox);
1782
2386
  holder.keeping = true;
1783
- await Promise.allSettled(holder.starting);
1784
- const stillRunning = (await Promise.all([...holder.running].map((command) => endProcess(holder, command)))).filter((ended) => !ended).length;
2387
+ if (!await settledUnlessAborted(holder.starting, signal)) return { ok: false, failure: { kind: "aborted" } };
2388
+ const stillRunning = (await Promise.all([...holder.running].map((command) => endProcess(holder, command, signal)))).filter((ended) => !ended).length;
2389
+ if (isAborted(signal)) return { ok: false, failure: { kind: "aborted" } };
1785
2390
  if (stillRunning > 0)
1786
2391
  return {
1787
2392
  ok: false,
@@ -1794,28 +2399,32 @@ function liveRunnerSandboxGateway() {
1794
2399
  const stopsAt = holder.sandbox.expiresAt;
1795
2400
  const short = request2.until.getTime() - (stopsAt?.getTime() ?? Date.now());
1796
2401
  if (short <= 0 && stopsAt !== void 0) return { ok: true, value: { stopsAt } };
1797
- await holder.sandbox.extendTimeout(short);
2402
+ if (signal === void 0) await holder.sandbox.extendTimeout(short);
2403
+ else await holder.sandbox.extendTimeout(short, { signal });
1798
2404
  return { ok: true, value: { stopsAt: holder.sandbox.expiresAt ?? request2.until } };
1799
2405
  } catch (error) {
1800
- return { ok: false, failure: sandboxFailure(error, void 0) };
2406
+ return { ok: false, failure: sandboxFailure(error, signal) };
1801
2407
  }
1802
2408
  },
1803
- async stop(sandbox) {
2409
+ async stop(sandbox, signal) {
1804
2410
  const holder = holding(sandbox);
2411
+ if (isAborted(signal)) return { ok: false, failure: { kind: "aborted" } };
1805
2412
  try {
1806
- await holder.sandbox.stop();
2413
+ if (signal === void 0) await holder.sandbox.stop();
2414
+ else await holder.sandbox.stop({ signal });
1807
2415
  return { ok: true };
1808
2416
  } catch (error) {
1809
- return { ok: false, failure: sandboxFailure(error, void 0) };
2417
+ return { ok: false, failure: sandboxFailure(error, signal) };
1810
2418
  }
1811
2419
  },
1812
- async delete(sandbox) {
2420
+ async delete(sandbox, signal) {
1813
2421
  const holder = holding(sandbox);
2422
+ if (isAborted(signal)) return { ok: false, failure: { kind: "aborted" } };
1814
2423
  try {
1815
- await holder.sandbox.delete({ deleteOrphanSnapshots: false });
2424
+ await holder.sandbox.delete({ deleteOrphanSnapshots: false, ...signal === void 0 ? {} : { signal } });
1816
2425
  return { ok: true };
1817
2426
  } catch (error) {
1818
- return { ok: false, failure: sandboxFailure(error, void 0) };
2427
+ return { ok: false, failure: sandboxFailure(error, signal) };
1819
2428
  }
1820
2429
  }
1821
2430
  };
@@ -1829,9 +2438,45 @@ function placement(request2) {
1829
2438
  resources: { vcpus: request2.vcpus },
1830
2439
  timeout: request2.timeoutMs,
1831
2440
  persistent: false,
1832
- tags: { ...request2.tags }
2441
+ tags: { ...request2.tags },
2442
+ networkPolicy: sdkNetworkPolicy(request2.networkPolicy)
1833
2443
  };
1834
2444
  }
2445
+ function sdkNetworkPolicy(policy) {
2446
+ switch (policy.kind) {
2447
+ case "allow-all":
2448
+ if (policy.credentials.length === 0) return "allow-all";
2449
+ return { allow: { "*": [], ...injectionRules(policy.credentials) } };
2450
+ case "custom":
2451
+ return {
2452
+ allow: {
2453
+ ...Object.fromEntries(policy.allowedDomains.map((domain) => [domain, []])),
2454
+ ...injectionRules(policy.credentials)
2455
+ }
2456
+ };
2457
+ case "deny-all":
2458
+ return "deny-all";
2459
+ }
2460
+ }
2461
+ function injectionRules(credentials2) {
2462
+ const byDomain = /* @__PURE__ */ new Map();
2463
+ for (const { domain, header, value, requests } of credentials2) {
2464
+ const group = byDomain.get(domain) ?? { requests, headers: {} };
2465
+ if (group.requests !== requests)
2466
+ throw new Error(`writeNetworkPolicy: the credentials for ${domain} differ in requests`);
2467
+ group.headers[header] = value;
2468
+ byDomain.set(domain, group);
2469
+ }
2470
+ const rules = {};
2471
+ for (const [domain, { requests, headers }] of byDomain)
2472
+ rules[domain] = requests === "all" ? [{ transform: [{ headers }] }] : [{ match: { method: ["GET", "HEAD"] }, transform: [{ headers }] }, { response: { statusCode: 403 } }];
2473
+ return rules;
2474
+ }
2475
+ function hideCredentialValues(message, policy) {
2476
+ let hidden = message;
2477
+ for (const { value } of policyCredentials(policy)) if (value !== "") hidden = hidden.split(value).join("<token>");
2478
+ return hidden;
2479
+ }
1835
2480
  function writes(directory, files) {
1836
2481
  return files.map((file) => ({ path: `${directory}/${file.name}`, content: file.content }));
1837
2482
  }
@@ -1848,16 +2493,17 @@ async function stagingDirectory(holder, signal) {
1848
2493
  holder.staging = directory;
1849
2494
  return directory;
1850
2495
  }
1851
- async function resolveExecutable(holder, request2) {
2496
+ async function resolveExecutable(holder, request2, signal) {
1852
2497
  if (request2.cmd.includes("/")) return request2.cmd;
1853
2498
  const found = await holder.sandbox.runCommand({
1854
2499
  cmd: "bash",
1855
2500
  args: ["-c", 'command -v -- "$1"', "_", request2.cmd],
1856
2501
  cwd: request2.cwd,
1857
- env: { ...request2.env }
2502
+ env: { ...request2.env },
2503
+ signal
1858
2504
  });
1859
2505
  if (found.exitCode !== 0) return request2.cmd;
1860
- const path = (await found.stdout()).trim();
2506
+ const path = (await found.stdout({ signal })).trim();
1861
2507
  return path.startsWith("/") ? path : request2.cmd;
1862
2508
  }
1863
2509
  async function startDetached(holder, params) {
@@ -1879,36 +2525,69 @@ async function follow(holder, command, onOutput, signal) {
1879
2525
  holder.running.delete(command);
1880
2526
  return { exitCode: typeof finished.exitCode === "number" ? finished.exitCode : null };
1881
2527
  }
1882
- async function endProcess(holder, command) {
1883
- for (const [signal, graceMs] of [
2528
+ async function endProcess(holder, command, signal) {
2529
+ for (const [kill, graceMs] of [
1884
2530
  ["SIGTERM", TERMINATE_GRACE_MS],
1885
2531
  ["SIGKILL", KILL_GRACE_MS]
1886
2532
  ]) {
1887
- await command.kill(signal).catch(() => void 0);
1888
- if (await endsWithin(command, graceMs)) {
2533
+ if (isAborted(signal)) return false;
2534
+ await withinLimit(graceMs, signal, (limit) => command.kill(kill, { abortSignal: limit })).catch(() => void 0);
2535
+ if (await endsWithin(command, graceMs, signal)) {
1889
2536
  holder.running.delete(command);
1890
2537
  return true;
1891
2538
  }
1892
2539
  }
1893
2540
  return false;
1894
2541
  }
1895
- async function endsWithin(command, ms) {
1896
- const timeout = new AbortController();
1897
- const timer = setTimeout(() => timeout.abort(), ms);
2542
+ async function endsWithin(command, ms, signal) {
1898
2543
  try {
1899
- await command.wait({ signal: timeout.signal });
2544
+ await withinLimit(ms, signal, (limit) => command.wait({ signal: limit }));
1900
2545
  return true;
1901
2546
  } catch {
1902
2547
  return false;
2548
+ }
2549
+ }
2550
+ async function withinLimit(ms, signal, call) {
2551
+ if (isAborted(signal)) throw new DOMException("This operation was aborted", "AbortError");
2552
+ const limit = new AbortController();
2553
+ const timer = setTimeout(() => limit.abort(), ms);
2554
+ const onAbort = () => limit.abort();
2555
+ signal?.addEventListener("abort", onAbort, { once: true });
2556
+ const aborted = new Promise((_, reject) => {
2557
+ limit.signal.addEventListener("abort", () => reject(new DOMException("This operation was aborted", "AbortError")), {
2558
+ once: true
2559
+ });
2560
+ });
2561
+ try {
2562
+ return await Promise.race([call(limit.signal), aborted]);
1903
2563
  } finally {
1904
2564
  clearTimeout(timer);
2565
+ signal?.removeEventListener("abort", onAbort);
1905
2566
  }
1906
2567
  }
1907
- function isAborted(signal) {
1908
- return signal?.aborted === true;
2568
+ async function settledUnlessAborted(tasks, signal) {
2569
+ if (isAborted(signal)) return false;
2570
+ if (signal === void 0 || tasks.size === 0) {
2571
+ await Promise.allSettled(tasks);
2572
+ return true;
2573
+ }
2574
+ return await untilAborted(Promise.allSettled(tasks), signal) !== ABORTED;
2575
+ }
2576
+ function isAborted(signal) {
2577
+ return signal?.aborted === true;
1909
2578
  }
1910
2579
 
1911
2580
  // src/runner/live/terminal.ts
2581
+ function resolveRunnerTerminalColor(options) {
2582
+ if (options.noColor === true) return "off";
2583
+ const noColor = options.env["NO_COLOR"];
2584
+ if (noColor !== void 0 && noColor !== "") return "off";
2585
+ const forced = options.env["FORCE_COLOR"];
2586
+ if (forced !== void 0 && forced !== "") {
2587
+ return forced === "0" || forced === "false" ? "auto" : "on";
2588
+ }
2589
+ return options.isTTY && options.env["TERM"] !== "dumb" ? "on" : "auto";
2590
+ }
1912
2591
  function liveRunnerTerminal(options) {
1913
2592
  const stdout = options.stdout ?? process.stdout;
1914
2593
  const stderr = options.stderr ?? process.stderr;
@@ -1931,7 +2610,11 @@ function liveRunnerTerminal(options) {
1931
2610
  }
1932
2611
  };
1933
2612
  return {
1934
- color: stdout.isTTY === true && options.env["NO_COLOR"] === void 0,
2613
+ color: resolveRunnerTerminalColor({
2614
+ isTTY: stdout.isTTY === true,
2615
+ env: options.env,
2616
+ ...options.noColor === void 0 ? {} : { noColor: options.noColor }
2617
+ }),
1935
2618
  writeStdout: (text) => write(stdout, text),
1936
2619
  writeStderr: (text) => write(stderr, text)
1937
2620
  };
@@ -2129,141 +2812,44 @@ async function prepareRunner(context, request2) {
2129
2812
  };
2130
2813
  }
2131
2814
 
2132
- // src/runner/sandboxed-command.ts
2133
- import { posix } from "node:path";
2134
- function sandboxedCommand(request2) {
2135
- const [first = "", ...rest] = request2.argv.map((argument) => rewritePaths(argument, request2.repoRoot, SANDBOX_ROOT));
2136
- const cmd = first.includes("/") && !first.startsWith("/") ? posix.join(request2.cwd, first) : first;
2137
- return { cmd, args: rest };
2138
- }
2139
- function sandboxEnvironment(request2) {
2140
- const bins = [
2141
- .../* @__PURE__ */ new Set([posix.join(request2.cwd, "node_modules/.bin"), posix.join(SANDBOX_ROOT, "node_modules/.bin")])
2142
- ];
2143
- return {
2144
- PATH: [...bins, request2.loginPath].filter((part) => part !== "").join(":"),
2145
- NO_UPDATE_NOTIFIER: "1",
2146
- ...request2.env["FORCE_COLOR"] !== void 0 || request2.env["NO_COLOR"] !== void 0 ? {} : request2.color ? { FORCE_COLOR: "1" } : { NO_COLOR: "1" },
2147
- ...request2.env,
2148
- [RUN_PAYLOAD_VARIABLE]: request2.runPayload
2149
- };
2150
- }
2151
- var SANDBOX_TEST_EVENTS_PATH = "/tmp/storm-test-events.jsonl";
2152
- async function runCommandInSandbox(context, request2, control, progress) {
2153
- const { runner } = request2;
2154
- const terminal = context.runnerTerminal;
2155
- const command = sandboxedCommand({ argv: request2.argv, repoRoot: runner.repoRoot, cwd: runner.cwd });
2156
- const env = sandboxEnvironment({
2157
- cwd: runner.cwd,
2158
- loginPath: runner.loginPath,
2159
- color: terminal.color,
2160
- env: runner.env,
2161
- runPayload: request2.runPayload
2162
- });
2163
- await progress.emit({ kind: "command-output-started", sandbox: runner.sandbox.name, region: runner.region });
2164
- const startedAt = context.clock.now().getTime();
2165
- const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
2166
- const write = (stream, text) => {
2167
- if (text === "") return;
2168
- const local = rewritePaths(text, SANDBOX_ROOT, runner.repoRoot);
2169
- if (stream === "stdout") terminal.writeStdout(local);
2170
- else terminal.writeStderr(local);
2171
- };
2172
- const following = followTestEvents(context, runner, request2.testEvents, control.kill);
2173
- const ran = await context.runnerSandboxes.runCommand(
2174
- runner.sandbox,
2175
- { cmd: command.cmd, args: command.args, cwd: runner.cwd, env },
2176
- ({ stream, data }) => write(stream, splitters[stream].push(data)),
2177
- control.kill
2178
- );
2179
- const ms = context.clock.now().getTime() - startedAt;
2180
- write("stdout", splitters.stdout.flush());
2181
- write("stderr", splitters.stderr.flush());
2182
- await following?.end(ran.ok && !control.kill.aborted);
2183
- if (!ran.ok) {
2184
- if (ran.failure.kind !== "aborted")
2185
- return { kind: "failed", failure: sandboxApiFailure("run-command", ran.failure) };
2186
- await progress.emit({ kind: "command-stopped", command: posix.basename(command.cmd) });
2187
- return { kind: "killed" };
2188
- }
2189
- return { kind: "exited", exitCode: ran.value.exitCode, ms };
2190
- }
2191
- function followTestEvents(context, runner, testEvents, kill) {
2192
- if (testEvents === void 0) return void 0;
2193
- const stop = new AbortController();
2194
- const splitter = lineSplitter();
2195
- let handed = 0;
2196
- const hand = (lines) => {
2197
- for (const line of lines) {
2198
- handed += 1;
2199
- testEvents.onLine(line);
2200
- }
2201
- };
2202
- const followed = context.runnerSandboxes.followTestEvents(
2203
- runner.sandbox,
2204
- { path: SANDBOX_TEST_EVENTS_PATH },
2205
- ({ data }) => hand(splitLines(splitter.push(data))),
2206
- stop.signal
2207
- );
2208
- return {
2209
- async end(complete) {
2210
- stop.abort();
2211
- await followed;
2212
- if (!complete) {
2213
- hand(splitLines(splitter.flush()));
2214
- return;
2215
- }
2216
- const reader = lineSplitter();
2217
- let read = false;
2218
- const result = await context.runnerSandboxes.readTestEvents(
2219
- runner.sandbox,
2220
- { path: SANDBOX_TEST_EVENTS_PATH, fromLine: handed + 1 },
2221
- ({ data }) => {
2222
- if (!read) {
2223
- splitter.flush();
2224
- read = true;
2225
- }
2226
- hand(splitLines(reader.push(data)));
2227
- },
2228
- kill
2229
- );
2230
- hand(splitLines(read ? reader.flush() : splitter.flush()));
2231
- if (!result.ok && result.failure.kind === "api") testEvents.onIncomplete(result.failure.message);
2232
- }
2233
- };
2234
- }
2235
-
2236
2815
  // src/runner/ready.ts
2237
- import { posix as posix2 } from "node:path";
2816
+ import { posix } from "node:path";
2238
2817
  var APPLY_LABEL = "Applying your changes";
2239
2818
  async function readyRunner(context, request2, control, progress) {
2819
+ const chosen = await chooseSnapshot(context, request2, control, progress);
2820
+ if (chosen.kind !== "ok") return chosen;
2821
+ return await readyFromSnapshot(context, { ...request2, snapshot: chosen.value }, control, progress);
2822
+ }
2823
+ async function chooseSnapshot(context, request2, control, progress) {
2240
2824
  const { prepared, access } = request2;
2241
- const { recipe, repoRoot } = prepared;
2242
- const { scope, signal } = control;
2243
- const now = () => context.clock.now().getTime();
2244
- if (signal.aborted) return { kind: "aborted" };
2825
+ if (control.signal.aborted) return { kind: "aborted" };
2245
2826
  const pick = pickSnapshot(prepared.candidates, access);
2246
- let entry;
2247
2827
  if (pick !== void 0) {
2248
- ({ entry } = pick);
2828
+ const { entry } = pick;
2249
2829
  await progress.emit({
2250
2830
  kind: "snapshot-reused",
2251
2831
  snapshotId: entry.snapshotId,
2252
2832
  base: entry.base,
2253
2833
  builtBehind: pick.builtBehind
2254
2834
  });
2255
- } else {
2256
- const why = { kind: "no-snapshot", rejected: snapshotRejections(prepared, access) };
2257
- const building = await buildSnapshot(
2258
- context,
2259
- { prepared, access, user: request2.user, secrets: request2.secrets, why },
2260
- control,
2261
- progress
2262
- );
2263
- if (building.kind !== "ok") return building;
2264
- ({ entry } = building.value);
2835
+ return { kind: "ok", value: { entry, built: false } };
2265
2836
  }
2266
- const built = pick === void 0;
2837
+ const why = { kind: "no-snapshot", rejected: snapshotRejections(prepared, access) };
2838
+ const building = await buildSnapshot(
2839
+ context,
2840
+ { prepared, access, user: request2.user, credentials: request2.credentials, why },
2841
+ control,
2842
+ progress
2843
+ );
2844
+ if (building.kind !== "ok") return building;
2845
+ return { kind: "ok", value: { entry: building.value.entry, built: true } };
2846
+ }
2847
+ async function readyFromSnapshot(context, request2, control, progress) {
2848
+ const { prepared, access } = request2;
2849
+ const { entry, built } = request2.snapshot;
2850
+ const { recipe, repoRoot } = prepared;
2851
+ const { scope, signal } = control;
2852
+ const now = () => context.clock.now().getTime();
2267
2853
  if (signal.aborted) return { kind: "aborted" };
2268
2854
  await progress.emit({ kind: "runner-sandbox-starting", snapshotId: entry.snapshotId });
2269
2855
  const startedAt = now();
@@ -2306,28 +2892,20 @@ async function readyRunner(context, request2, control, progress) {
2306
2892
  if (applied.kind !== "ok") return applied;
2307
2893
  const loginPath = await context.runnerSandboxes.loginPath(sandbox, signal);
2308
2894
  if (!loginPath.ok) return sandboxStop("login-path", loginPath.failure);
2895
+ if (request2.credentials.length > 0) {
2896
+ const granted = await scope.grantCredentials(sandbox, request2.credentials, signal);
2897
+ if (!granted.ok) return networkPolicyStop("inject", "run-steps", granted.failure);
2898
+ }
2309
2899
  const installed = await stage(
2310
2900
  context,
2311
- {
2312
- sandbox,
2313
- phase: "install",
2314
- step: recipe.run.install,
2315
- secrets: stepSecrets(request2.secrets, recipe.run.install.secrets),
2316
- region: recipe.region
2317
- },
2901
+ { sandbox, phase: "install", step: recipe.run.install, region: recipe.region },
2318
2902
  signal,
2319
2903
  progress
2320
2904
  );
2321
2905
  if (installed.kind !== "ok") return installed;
2322
2906
  const builtOutputs = await stage(
2323
2907
  context,
2324
- {
2325
- sandbox,
2326
- phase: "build",
2327
- step: recipe.run.build,
2328
- secrets: stepSecrets(request2.secrets, recipe.run.build.secrets),
2329
- region: recipe.region
2330
- },
2908
+ { sandbox, phase: "build", step: recipe.run.build, region: recipe.region },
2331
2909
  signal,
2332
2910
  progress
2333
2911
  );
@@ -2346,122 +2924,280 @@ async function readyRunner(context, request2, control, progress) {
2346
2924
  region: recipe.region,
2347
2925
  runtime: recipe.runtime,
2348
2926
  repoRoot,
2349
- cwd: posix2.join(SANDBOX_ROOT, recipe.cwd),
2927
+ cwd: posix.join(SANDBOX_ROOT, recipe.cwd),
2350
2928
  env: recipe.env,
2351
2929
  loginPath: loginPath.value
2352
2930
  }
2353
2931
  };
2354
2932
  }
2355
- async function uploadChanges(context, request2, signal, progress) {
2356
- await progress.emit({ kind: "uploading" });
2357
- const startedAt = context.clock.now().getTime();
2358
- const files = stagedChanges(request2.prepared.upload);
2359
- const staged = await context.runnerSandboxes.upload(request2.sandbox, files, signal);
2360
- if (!staged.ok) return sandboxStop("upload", staged.failure);
2361
- const bytes = files.reduce((sum, file) => sum + file.content.byteLength, 0);
2362
- await progress.emit({ kind: "uploaded", bytes, ms: context.clock.now().getTime() - startedAt });
2363
- return { kind: "ok", value: { directory: staged.value.directory, bytes } };
2364
- }
2365
- function stagedChanges(upload) {
2366
- const encoder = new TextEncoder();
2367
- return [
2368
- { name: STAGED_FILES.patch, content: upload.patch },
2369
- {
2370
- name: STAGED_FILES.untrackedFileList,
2371
- content: encoder.encode(upload.untracked.map((path) => `${path}\0`).join(""))
2372
- },
2373
- ...upload.untrackedTarball === void 0 ? [] : [{ name: STAGED_FILES.untrackedTarball, content: upload.untrackedTarball }]
2374
- ];
2375
- }
2376
- async function stage(context, request2, signal, progress) {
2377
- if (signal.aborted) return { kind: "aborted" };
2378
- const { sandbox, phase, step } = request2;
2379
- const section = phase === "apply" ? void 0 : phase;
2380
- if (section !== void 0)
2381
- await progress.emit({ kind: "output-started", section, sandbox: sandbox.name, region: request2.region });
2382
- const ran = await runStep(
2383
- context,
2384
- {
2385
- sandbox,
2386
- phase,
2387
- label: step.label,
2388
- script: step.script,
2389
- ...request2.secrets === void 0 ? {} : { secrets: request2.secrets }
2390
- },
2391
- progress,
2392
- signal
2393
- );
2394
- if (ran.kind === "succeeded") {
2395
- if (section !== void 0) await progress.emit({ kind: "output-ended", section, outcome: "finished" });
2396
- return { kind: "ok", value: ran.ms };
2397
- }
2398
- const stop = ran.kind === "exited" ? {
2399
- kind: "failed",
2400
- failure: { kind: `${phase}-failed`, label: step.label, exitCode: ran.exitCode, tail: ran.tail }
2401
- } : sandboxStop("run-script", ran.failure);
2402
- if (section !== void 0)
2403
- await progress.emit({ kind: "output-ended", section, outcome: stop.kind === "aborted" ? "stopped" : "failed" });
2404
- return stop;
2933
+ async function uploadChanges(context, request2, signal, progress) {
2934
+ await progress.emit({ kind: "uploading" });
2935
+ const startedAt = context.clock.now().getTime();
2936
+ const files = stagedChanges(request2.prepared.upload);
2937
+ const staged = await context.runnerSandboxes.upload(request2.sandbox, files, signal);
2938
+ if (!staged.ok) return sandboxStop("upload", staged.failure);
2939
+ const bytes = files.reduce((sum, file) => sum + file.content.byteLength, 0);
2940
+ await progress.emit({ kind: "uploaded", bytes, ms: context.clock.now().getTime() - startedAt });
2941
+ return { kind: "ok", value: { directory: staged.value.directory, bytes } };
2942
+ }
2943
+ function stagedChanges(upload) {
2944
+ const encoder = new TextEncoder();
2945
+ return [
2946
+ { name: STAGED_FILES.patch, content: upload.patch },
2947
+ {
2948
+ name: STAGED_FILES.untrackedFileList,
2949
+ content: encoder.encode(upload.untracked.map((path) => `${path}\0`).join(""))
2950
+ },
2951
+ ...upload.untrackedTarball === void 0 ? [] : [{ name: STAGED_FILES.untrackedTarball, content: upload.untrackedTarball }]
2952
+ ];
2953
+ }
2954
+ async function stage(context, request2, signal, progress) {
2955
+ if (signal.aborted) return { kind: "aborted" };
2956
+ const { sandbox, phase, step } = request2;
2957
+ const section = phase === "apply" ? void 0 : phase;
2958
+ if (section !== void 0)
2959
+ await progress.emit({ kind: "output-started", section, sandbox: sandbox.name, region: request2.region });
2960
+ const ran = await runStep(context, { sandbox, phase, label: step.label, script: step.script }, progress, signal);
2961
+ if (ran.kind === "succeeded") {
2962
+ if (section !== void 0) await progress.emit({ kind: "output-ended", section, outcome: "finished" });
2963
+ return { kind: "ok", value: ran.ms };
2964
+ }
2965
+ const stop = ran.kind === "exited" ? {
2966
+ kind: "failed",
2967
+ failure: { kind: `${phase}-failed`, label: step.label, exitCode: ran.exitCode, tail: ran.tail }
2968
+ } : sandboxStop("run-script", ran.failure);
2969
+ if (section !== void 0)
2970
+ await progress.emit({ kind: "output-ended", section, outcome: stop.kind === "aborted" ? "stopped" : "failed" });
2971
+ return stop;
2972
+ }
2973
+
2974
+ // src/runner/snapshot-choice.ts
2975
+ async function chooseSnapshotForRun(context, request2, control, progress) {
2976
+ const { signal, stop } = control;
2977
+ const stageSignal = stop === void 0 ? signal : AbortSignal.any([signal, stop]);
2978
+ const scope = runnerSandboxScope(context, progress, {
2979
+ keepMs: 0,
2980
+ basePolicy: runnerNetworkPolicy(request2.prepared.recipe),
2981
+ signal
2982
+ });
2983
+ try {
2984
+ const chosen = await chooseSnapshot(context, request2, { scope, signal: stageSignal }, progress);
2985
+ const cleanup = await scope.close();
2986
+ if (chosen.kind !== "ok") return { ...chosen, cleanup };
2987
+ if (stageSignal.aborted) return { kind: "aborted", cleanup };
2988
+ return { kind: "chosen", snapshot: chosen.value, cleanup };
2989
+ } catch (error) {
2990
+ await scope.close();
2991
+ throw error;
2992
+ }
2993
+ }
2994
+
2995
+ // src/runner/sandboxed-command.ts
2996
+ import { posix as posix2 } from "node:path";
2997
+ function sandboxedCommand(request2) {
2998
+ const [first = "", ...rest] = request2.argv.map((argument) => rewritePaths(argument, request2.repoRoot, SANDBOX_ROOT));
2999
+ const cmd = first.includes("/") && !first.startsWith("/") ? posix2.join(request2.cwd, first) : first;
3000
+ return { cmd, args: rest };
3001
+ }
3002
+ function sandboxEnvironment(request2) {
3003
+ const bins = [
3004
+ .../* @__PURE__ */ new Set([posix2.join(request2.cwd, "node_modules/.bin"), posix2.join(SANDBOX_ROOT, "node_modules/.bin")])
3005
+ ];
3006
+ return {
3007
+ PATH: [...bins, request2.loginPath].filter((part) => part !== "").join(":"),
3008
+ NO_UPDATE_NOTIFIER: "1",
3009
+ ...request2.env["FORCE_COLOR"] !== void 0 || request2.env["NO_COLOR"] !== void 0 ? {} : request2.color === "on" ? { FORCE_COLOR: "1" } : request2.color === "off" ? { NO_COLOR: "1" } : {},
3010
+ ...request2.env,
3011
+ ...request2.unsafeSecretEnvVars,
3012
+ [RUN_PAYLOAD_VARIABLE]: request2.runPayload
3013
+ };
3014
+ }
3015
+ var TEST_EVENTS_END_LIMIT_MS = 3e4;
3016
+ var SANDBOX_TEST_EVENTS_PATH = "/tmp/storm-test-events.jsonl";
3017
+ async function runCommandInSandbox(context, request2, control, progress) {
3018
+ const { runner } = request2;
3019
+ const terminal = context.runnerTerminal;
3020
+ const command = sandboxedCommand({ argv: request2.argv, repoRoot: runner.repoRoot, cwd: runner.cwd });
3021
+ const env = sandboxEnvironment({
3022
+ cwd: runner.cwd,
3023
+ loginPath: runner.loginPath,
3024
+ color: terminal.color,
3025
+ env: runner.env,
3026
+ ...request2.unsafeSecretEnvVars === void 0 ? {} : { unsafeSecretEnvVars: request2.unsafeSecretEnvVars },
3027
+ runPayload: request2.runPayload
3028
+ });
3029
+ await progress.emit({ kind: "command-output-started", sandbox: runner.sandbox.name, region: runner.region });
3030
+ const startedAt = context.clock.now().getTime();
3031
+ const splitters = { stdout: lineSplitter(), stderr: lineSplitter() };
3032
+ const write = (stream, text) => {
3033
+ if (text === "") return;
3034
+ const local = rewritePaths(text, SANDBOX_ROOT, runner.repoRoot);
3035
+ if (stream === "stdout") terminal.writeStdout(local);
3036
+ else terminal.writeStderr(local);
3037
+ };
3038
+ const following = followTestEvents(context, runner, request2.testEvents, control.kill);
3039
+ const ran = await context.runnerSandboxes.runCommand(
3040
+ runner.sandbox,
3041
+ { cmd: command.cmd, args: command.args, cwd: runner.cwd, env },
3042
+ ({ stream, data }) => write(stream, splitters[stream].push(data)),
3043
+ control.kill
3044
+ );
3045
+ const ms = context.clock.now().getTime() - startedAt;
3046
+ write("stdout", splitters.stdout.flush());
3047
+ write("stderr", splitters.stderr.flush());
3048
+ await following?.end(ran.ok && !control.kill.aborted);
3049
+ if (!ran.ok) {
3050
+ if (ran.failure.kind !== "aborted")
3051
+ return { kind: "failed", failure: sandboxApiFailure("run-command", ran.failure) };
3052
+ await progress.emit({ kind: "command-stopped", command: posix2.basename(command.cmd) });
3053
+ return { kind: "killed" };
3054
+ }
3055
+ return { kind: "exited", exitCode: ran.value.exitCode, ms };
3056
+ }
3057
+ function followTestEvents(context, runner, testEvents, kill) {
3058
+ if (testEvents === void 0) return void 0;
3059
+ const stop = new AbortController();
3060
+ const splitter = lineSplitter();
3061
+ let handed = 0;
3062
+ const hand = (lines) => {
3063
+ for (const line of lines) {
3064
+ handed += 1;
3065
+ testEvents.onLine(line);
3066
+ }
3067
+ };
3068
+ const followed = context.runnerSandboxes.followTestEvents(
3069
+ runner.sandbox,
3070
+ { path: SANDBOX_TEST_EVENTS_PATH },
3071
+ ({ data }) => hand(splitLines(splitter.push(data))),
3072
+ stop.signal
3073
+ );
3074
+ return {
3075
+ async end(complete) {
3076
+ stop.abort();
3077
+ const stopped = await callWithin(context.timer, TEST_EVENTS_END_LIMIT_MS, () => followed);
3078
+ if (stopped === null) {
3079
+ hand(splitLines(splitter.flush()));
3080
+ if (complete) testEvents.onIncomplete(`following the test events file didn't stop within ${limitWords()}`);
3081
+ return;
3082
+ }
3083
+ if (!complete) {
3084
+ hand(splitLines(splitter.flush()));
3085
+ return;
3086
+ }
3087
+ const reader = lineSplitter();
3088
+ let read = false;
3089
+ const result = await callWithin(
3090
+ context.timer,
3091
+ TEST_EVENTS_END_LIMIT_MS,
3092
+ (signal) => context.runnerSandboxes.readTestEvents(
3093
+ runner.sandbox,
3094
+ { path: SANDBOX_TEST_EVENTS_PATH, fromLine: handed + 1 },
3095
+ ({ data }) => {
3096
+ if (!read) {
3097
+ splitter.flush();
3098
+ read = true;
3099
+ }
3100
+ hand(splitLines(reader.push(data)));
3101
+ },
3102
+ AbortSignal.any([kill, signal])
3103
+ )
3104
+ );
3105
+ hand(splitLines(read ? reader.flush() : splitter.flush()));
3106
+ if (result === null)
3107
+ testEvents.onIncomplete(`the final read of the test events file had no answer within ${limitWords()}`);
3108
+ else if (!result.ok && result.failure.kind === "api") testEvents.onIncomplete(result.failure.message);
3109
+ }
3110
+ };
3111
+ }
3112
+ function limitWords() {
3113
+ return `${TEST_EVENTS_END_LIMIT_MS / 1e3} seconds`;
2405
3114
  }
2406
3115
 
2407
3116
  // src/runner/session.ts
2408
3117
  function openRunnerSession(context, request2, control, progress) {
2409
3118
  const { signal, cleanup } = control;
2410
- const scope = runnerSandboxScope(context, progress, { keepMs: request2.keepMs });
2411
- const closeScope = async () => ({ ...await scope.close(), target: request2.target });
3119
+ const unsafeSecretEnvVars = request2.unsafeSecretEnvVars ?? {};
3120
+ const hasUnsafeSecretEnvVars = Object.keys(unsafeSecretEnvVars).length > 0;
3121
+ if (hasUnsafeSecretEnvVars && request2.keepMs > 0)
3122
+ throw new Error("a runner session with unsafeSecretEnvVars can't keep its runner sandbox");
3123
+ let commandRunning = false;
3124
+ const scope = runnerSandboxScope(context, progress, {
3125
+ keepMs: request2.keepMs,
3126
+ basePolicy: runnerNetworkPolicy(request2.prepared.recipe),
3127
+ signal,
3128
+ commandRunning: () => commandRunning
3129
+ });
3130
+ let cleaning;
3131
+ const cleanUp = () => cleaning ??= (async () => {
3132
+ let runnerSandboxFenced = false;
3133
+ try {
3134
+ try {
3135
+ await cleanup.startCleanup();
3136
+ } finally {
3137
+ ({ runnerSandboxFenced } = await scope.fence());
3138
+ }
3139
+ } finally {
3140
+ try {
3141
+ await cleanup.release({ runnerSandboxFenced });
3142
+ } finally {
3143
+ await scope.close();
3144
+ }
3145
+ }
3146
+ return { ...await scope.close(), target: request2.target };
3147
+ })();
2412
3148
  let readying = false;
2413
3149
  let readied;
2414
- let commandRunning = false;
2415
- const stop = () => {
2416
- void progress.emit({ kind: "stopping", commandRunning, keepMs: request2.keepMs }).catch(() => void 0);
2417
- void scope.close().catch(() => void 0);
2418
- };
2419
- if (signal.aborted) stop();
2420
- else signal.addEventListener("abort", stop, { once: true });
2421
3150
  return {
2422
3151
  async ready(access, laneSignal) {
2423
3152
  if (readying) throw new Error("the runner session readies its runner sandbox once");
2424
3153
  readying = true;
2425
- const { prepared, user, secrets } = request2;
2426
- const outcome = await readyRunner(
2427
- context,
2428
- { prepared, access, user, secrets },
2429
- { scope, signal: laneSignal },
2430
- progress
2431
- );
3154
+ const { prepared, user, credentials: credentials2, snapshot } = request2;
3155
+ const stage2 = { scope, signal: laneSignal };
3156
+ const outcome = snapshot === void 0 ? await readyRunner(context, { prepared, access, user, credentials: credentials2 }, stage2, progress) : await readyFromSnapshot(context, { prepared, access, user, credentials: credentials2, snapshot }, stage2, progress);
2432
3157
  if (outcome.kind === "ready") readied = outcome.runner;
2433
3158
  return outcome;
2434
3159
  },
2435
3160
  async runCommand(command) {
2436
3161
  if (readied === void 0) throw new Error("the runner session's runner sandbox isn't ready");
3162
+ const runner = readied;
2437
3163
  commandRunning = true;
2438
- return await runCommandInSandbox(
2439
- context,
2440
- {
2441
- runner: readied,
2442
- argv: command.argv,
2443
- runPayload: command.runPayload,
2444
- ...command.testEvents === void 0 ? {} : { testEvents: command.testEvents }
2445
- },
2446
- { kill: signal },
2447
- progress
2448
- );
2449
- },
2450
- async finish() {
2451
- commandRunning = false;
2452
- await cleanup.startCleanup();
2453
- const facts = await closeScope();
2454
- signal.removeEventListener("abort", stop);
2455
- await cleanup.release();
2456
- return facts;
2457
- },
2458
- async close() {
2459
- signal.removeEventListener("abort", stop);
2460
3164
  try {
2461
- return await closeScope();
3165
+ const run = () => runCommandInSandbox(
3166
+ context,
3167
+ {
3168
+ runner,
3169
+ argv: command.argv,
3170
+ runPayload: command.runPayload,
3171
+ ...hasUnsafeSecretEnvVars ? { unsafeSecretEnvVars } : {},
3172
+ ...command.testEvents === void 0 ? {} : { testEvents: command.testEvents }
3173
+ },
3174
+ { kill: signal },
3175
+ progress
3176
+ );
3177
+ const resourceCredentials = command.credentials ?? [];
3178
+ const granted = request2.credentials.length > 0 || resourceCredentials.length > 0;
3179
+ try {
3180
+ if (resourceCredentials.length > 0) {
3181
+ const both = await scope.grantCredentials(
3182
+ runner.sandbox,
3183
+ [...request2.credentials, ...resourceCredentials],
3184
+ signal
3185
+ );
3186
+ if (!both.ok) {
3187
+ const stop = networkPolicyStop("inject", "command", both.failure);
3188
+ return stop.kind === "aborted" ? { kind: "killed" } : { kind: "failed", failure: stop.failure };
3189
+ }
3190
+ }
3191
+ return await run();
3192
+ } finally {
3193
+ if (granted) await scope.revokeCredentials(runner.sandbox);
3194
+ }
2462
3195
  } finally {
2463
- await cleanup.release();
3196
+ commandRunning = false;
2464
3197
  }
3198
+ },
3199
+ async cleanUp() {
3200
+ return await cleanUp();
2465
3201
  }
2466
3202
  };
2467
3203
  }
@@ -2469,6 +3205,45 @@ function openRunnerSession(context, request2, control, progress) {
2469
3205
  // src/config/load.ts
2470
3206
  import { dirname, join as join2 } from "node:path";
2471
3207
 
3208
+ // src/config/check-runner.ts
3209
+ var FACTORY_HINT = "must be made by vercelSandbox({ \u2026 }) or launchMachine()";
3210
+ function checkRunner(value, inherited) {
3211
+ if (!isRecord2(value)) {
3212
+ return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not ${describeValue(value)}` }] };
3213
+ }
3214
+ const kind2 = value["kind"];
3215
+ if (kind2 === "launch-machine") {
3216
+ const extraKeys = Object.keys(value).filter((key) => key !== "kind");
3217
+ if (extraKeys.length > 0) {
3218
+ return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not an object` }] };
3219
+ }
3220
+ return { ok: true, value: { kind: "launch-machine" } };
3221
+ }
3222
+ if (kind2 === "vercel-sandbox") {
3223
+ const extraKeys = Object.keys(value).filter((key) => key !== "kind" && key !== "options");
3224
+ const options = value["options"];
3225
+ if (extraKeys.length > 0 || !isRecord2(options)) {
3226
+ return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not an object` }] };
3227
+ }
3228
+ const rawOptions = inherited === void 0 ? options : {
3229
+ ...inherited,
3230
+ ...Object.fromEntries(Object.entries(options).filter(([, entry]) => entry !== void 0))
3231
+ };
3232
+ const checked = checkRecipe(rawOptions);
3233
+ if (!checked.ok) return checked;
3234
+ return { ok: true, value: { kind: "vercel-sandbox", recipe: checked.value } };
3235
+ }
3236
+ return { ok: false, problems: [{ path: [], problem: `${FACTORY_HINT}, not ${describeValue(value)}` }] };
3237
+ }
3238
+ function rawVercelSandboxOptions(value) {
3239
+ if (!isRecord2(value) || value["kind"] !== "vercel-sandbox") return void 0;
3240
+ const options = value["options"];
3241
+ return isRecord2(options) ? options : void 0;
3242
+ }
3243
+ function isRecord2(value) {
3244
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3245
+ }
3246
+
2472
3247
  // src/config/schema.ts
2473
3248
  var CONFIG_FILE_NAME = "storm.config.ts";
2474
3249
  function checkWith(schema, value) {
@@ -2479,87 +3254,47 @@ function checkWith(schema, value) {
2479
3254
  problems: parsed.error.issues.map(({ path, message }) => ({ path: path.map(String), problem: message }))
2480
3255
  };
2481
3256
  }
3257
+ function checkStringList(value) {
3258
+ if (!Array.isArray(value)) {
3259
+ return { ok: false, problems: [{ path: [], problem: `must be a list of strings, not ${describeValue(value)}` }] };
3260
+ }
3261
+ const problems = [];
3262
+ for (let index = 0; index < value.length; index += 1) {
3263
+ if (typeof value[index] !== "string") {
3264
+ problems.push({ path: [String(index)], problem: `must be a string, not ${describeValue(value[index])}` });
3265
+ }
3266
+ }
3267
+ return problems.length === 0 ? { ok: true, value: [...value] } : { ok: false, problems };
3268
+ }
3269
+ function checkDriver(value, drivers) {
3270
+ const checked = checkWith(nonEmptyString, value);
3271
+ if (!checked.ok) return checked;
3272
+ if (!drivers.includes(checked.value)) {
3273
+ const available = drivers.length === 0 ? "none" : drivers.join(", ");
3274
+ return { ok: false, problems: [{ path: [], problem: `is not a driver; storm has ${available}` }] };
3275
+ }
3276
+ return checked;
3277
+ }
2482
3278
  var SETTING_CHECKS = {
2483
3279
  scope: (value) => checkWith(nonEmptyString, value),
2484
3280
  project: (value) => checkWith(nonEmptyString, value),
2485
- runner: checkRecipe,
3281
+ driver: (value, { drivers }) => checkDriver(value, drivers),
3282
+ args: checkStringList,
3283
+ runner: (value, { topLevelRunnerOptions }) => checkRunner(value, topLevelRunnerOptions),
2486
3284
  testPlan: (value) => checkWith(booleanOption, value)
2487
3285
  };
2488
3286
  function isConfigSettingKey(key) {
2489
3287
  return Object.hasOwn(SETTING_CHECKS, key);
2490
3288
  }
2491
- function checkSettingValue(key, value) {
2492
- return SETTING_CHECKS[key](value);
3289
+ function checkSettingValue(key, value, context) {
3290
+ return SETTING_CHECKS[key](value, context);
2493
3291
  }
2494
3292
 
2495
- // src/config/load.ts
2496
- async function findConfigFile(gateway, startDirectory) {
2497
- if (await gateway.hasConfigFile(startDirectory)) return join2(startDirectory, CONFIG_FILE_NAME);
2498
- const root = await worktreeRoot(gateway, startDirectory);
2499
- if (root === void 0) return void 0;
2500
- for (let directory = startDirectory; directory !== root; ) {
2501
- directory = dirname(directory);
2502
- if (await gateway.hasConfigFile(directory)) return join2(directory, CONFIG_FILE_NAME);
2503
- }
2504
- return void 0;
2505
- }
2506
- async function worktreeRoot(gateway, directory) {
2507
- for (let current = directory; ; current = dirname(current)) {
2508
- if (await gateway.isWorktreeRoot(current)) return current;
2509
- if (dirname(current) === current) return void 0;
2510
- }
2511
- }
2512
- async function loadConfig(gateway, startDirectory, definitions) {
2513
- const path = await findConfigFile(gateway, startDirectory);
2514
- if (path === void 0) return { kind: "none" };
2515
- const imported = await gateway.importConfig(path);
2516
- switch (imported.kind) {
2517
- case "import-failed":
2518
- return {
2519
- kind: "invalid",
2520
- path,
2521
- problems: [{ key: null, location: imported.location ?? null, problem: imported.message }]
2522
- };
2523
- case "no-default-export":
2524
- return {
2525
- kind: "invalid",
2526
- path,
2527
- problems: [fileProblem("has no default export; export default defineConfig({ \u2026 })")]
2528
- };
2529
- case "default-export":
2530
- return checkFile(path, imported.value, definitions);
2531
- }
2532
- }
2533
- function checkFile(path, value, definitions) {
2534
- if (!isRecord2(value))
2535
- return {
2536
- kind: "invalid",
2537
- path,
2538
- problems: [fileProblem(`must default-export an object, not ${describeValue(value)}`)]
2539
- };
2540
- const settings = {};
2541
- const problems = [];
2542
- let resources = {};
2543
- for (const [key, keyValue] of Object.entries(value)) {
2544
- if (key === "resources") resources = checkResources(keyValue, definitions, problems);
2545
- else if (isConfigSettingKey(key)) {
2546
- if (keyValue !== void 0) checkSetting(key, keyValue, settings, problems);
2547
- } else problems.push({ key, location: null, problem: `is not a ${CONFIG_FILE_NAME} key` });
2548
- }
2549
- if (problems.length > 0) return { kind: "invalid", path, problems };
2550
- return { kind: "loaded", path, values: { settings, resources } };
2551
- }
2552
- function checkSetting(key, value, settings, problems) {
2553
- const checked = checkSettingValue(key, value);
2554
- if (checked.ok) Object.assign(settings, { [key]: checked.value });
2555
- else
2556
- for (const { path: inside, problem } of checked.problems)
2557
- problems.push({ key: [key, ...inside].join("."), location: null, problem });
2558
- }
2559
- function checkResources(value, definitions, problems) {
3293
+ // src/config/check-resources.ts
3294
+ function checkResources(value, definitions, problems, at) {
2560
3295
  if (value === void 0) return {};
2561
- if (!isRecord2(value)) {
2562
- problems.push({ key: "resources", location: null, problem: `must be an object, not ${describeValue(value)}` });
3296
+ if (!isRecord3(value)) {
3297
+ problems.push({ key: at, location: null, problem: `must be an object, not ${describeValue(value)}` });
2563
3298
  return {};
2564
3299
  }
2565
3300
  const byName = new Map(definitions.map((definition) => [definition.name, definition]));
@@ -2570,7 +3305,7 @@ function checkResources(value, definitions, problems) {
2570
3305
  const definition = byName.get(named !== void 0 && byName.has(named) ? named : key);
2571
3306
  if (named !== void 0 && definition !== void 0 && key !== defaultResourceKey(definition)) {
2572
3307
  problems.push({
2573
- key: `resources.${key}`,
3308
+ key: `${at}.${key}`,
2574
3309
  location: null,
2575
3310
  problem: `holds a ${named} resource; for now a resource's key must be its definition's name: name its key ${defaultResourceKey(definition)}`
2576
3311
  });
@@ -2578,27 +3313,27 @@ function checkResources(value, definitions, problems) {
2578
3313
  }
2579
3314
  if (definition === void 0) {
2580
3315
  problems.push({
2581
- key: `resources.${key}`,
3316
+ key: `${at}.${key}`,
2582
3317
  location: null,
2583
3318
  problem: `is not a resource; resources holds ${holds}`
2584
3319
  });
2585
3320
  continue;
2586
3321
  }
2587
3322
  if (resource === void 0) continue;
2588
- const options = checkResource(definition, key, resource, problems);
3323
+ const options = checkResource(definition, `${at}.${key}`, resource, problems);
2589
3324
  if (options !== void 0) found[key] = { definition: definition.name, options };
2590
3325
  }
2591
3326
  return found;
2592
3327
  }
2593
3328
  function entryName(value) {
2594
- return isRecord2(value) && typeof value["name"] === "string" ? value["name"] : void 0;
3329
+ return isRecord3(value) && typeof value["name"] === "string" ? value["name"] : void 0;
2595
3330
  }
2596
- function checkResource(definition, key, value, problems) {
3331
+ function checkResource(definition, at, value, problems) {
2597
3332
  const { name } = definition;
2598
- const options = isRecord2(value) && value["name"] === name ? value["options"] : void 0;
2599
- if (!isRecord2(options)) {
3333
+ const options = isRecord3(value) && value["name"] === name ? value["options"] : void 0;
3334
+ if (!isRecord3(options)) {
2600
3335
  problems.push({
2601
- key: `resources.${key}`,
3336
+ key: at,
2602
3337
  location: null,
2603
3338
  problem: `must be made by ${resourceCall(name)}, not ${describeValue(value)}`
2604
3339
  });
@@ -2607,7 +3342,7 @@ function checkResource(definition, key, value, problems) {
2607
3342
  const checked = {};
2608
3343
  let valid = true;
2609
3344
  for (const [option, optionValue] of Object.entries(options)) {
2610
- const path = `resources.${key}.${option}`;
3345
+ const path = `${at}.${option}`;
2611
3346
  const rule = Object.hasOwn(definition.options, option) ? definition.options[option] : void 0;
2612
3347
  if (rule === void 0) {
2613
3348
  valid = false;
@@ -2625,7 +3360,178 @@ function checkResource(definition, key, value, problems) {
2625
3360
  }
2626
3361
  return valid ? checked : void 0;
2627
3362
  }
2628
- function isRecord2(value) {
3363
+ function isRecord3(value) {
3364
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3365
+ }
3366
+
3367
+ // src/config/suite.ts
3368
+ var SUITE_NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/u;
3369
+
3370
+ // src/config/check-suites.ts
3371
+ var SUITE_KEYS = /* @__PURE__ */ new Set(["driver", "args", "runner", "resources"]);
3372
+ function checkSuites(value, options, problems) {
3373
+ if (value === void 0) return {};
3374
+ if (!isRecord4(value)) {
3375
+ problems.push({ key: "suites", location: null, problem: `must be an object, not ${describeValue(value)}` });
3376
+ return {};
3377
+ }
3378
+ const settingContext = {
3379
+ drivers: options.drivers,
3380
+ topLevelRunnerOptions: options.topLevelRunnerOptions
3381
+ };
3382
+ const checked = {};
3383
+ for (const [name, raw] of Object.entries(value)) {
3384
+ const at = `suites.${name}`;
3385
+ if (!SUITE_NAME_PATTERN.test(name)) {
3386
+ problems.push({
3387
+ key: at,
3388
+ location: null,
3389
+ problem: "must hold only lowercase letters, digits, and hyphens, starting with a letter or a digit"
3390
+ });
3391
+ }
3392
+ if (!isRecord4(raw)) {
3393
+ problems.push({ key: at, location: null, problem: `must be an object, not ${describeValue(raw)}` });
3394
+ continue;
3395
+ }
3396
+ let driver;
3397
+ let hasOwnDriverKey = false;
3398
+ let args;
3399
+ let runner;
3400
+ let resources = {};
3401
+ for (const [key, keyValue] of Object.entries(raw)) {
3402
+ if (!SUITE_KEYS.has(key)) {
3403
+ problems.push({ key: `${at}.${key}`, location: null, problem: "is not a suite key" });
3404
+ continue;
3405
+ }
3406
+ if (keyValue === void 0) continue;
3407
+ if (key === "driver") {
3408
+ hasOwnDriverKey = true;
3409
+ const result = checkSettingValue("driver", keyValue, settingContext);
3410
+ if (result.ok) driver = result.value;
3411
+ else
3412
+ for (const { path: inside, problem } of result.problems)
3413
+ problems.push({ key: [`${at}.driver`, ...inside].join("."), location: null, problem });
3414
+ } else if (key === "args") {
3415
+ const result = checkSettingValue("args", keyValue, settingContext);
3416
+ if (result.ok) args = result.value;
3417
+ else
3418
+ for (const { path: inside, problem } of result.problems)
3419
+ problems.push({ key: [`${at}.args`, ...inside].join("."), location: null, problem });
3420
+ } else if (key === "runner") {
3421
+ const result = checkSettingValue("runner", keyValue, settingContext);
3422
+ if (result.ok) runner = result.value;
3423
+ else
3424
+ for (const { path: inside, problem } of result.problems)
3425
+ problems.push({ key: [`${at}.runner`, ...inside].join("."), location: null, problem });
3426
+ } else if (key === "resources") {
3427
+ resources = checkResources(keyValue, options.definitions, problems, `${at}.resources`);
3428
+ }
3429
+ }
3430
+ if (!hasOwnDriverKey && !options.hasTopLevelDriver) {
3431
+ problems.push({
3432
+ key: `${at}.driver`,
3433
+ location: null,
3434
+ problem: "must name a driver when the top level names none"
3435
+ });
3436
+ }
3437
+ checked[name] = {
3438
+ ...driver === void 0 ? {} : { driver },
3439
+ ...args === void 0 ? {} : { args },
3440
+ ...runner === void 0 ? {} : { runner },
3441
+ resources
3442
+ };
3443
+ }
3444
+ return checked;
3445
+ }
3446
+ function isRecord4(value) {
3447
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3448
+ }
3449
+
3450
+ // src/config/load.ts
3451
+ async function findConfigFile(gateway, startDirectory) {
3452
+ if (await gateway.hasConfigFile(startDirectory)) return join2(startDirectory, CONFIG_FILE_NAME);
3453
+ const root = await worktreeRoot(gateway, startDirectory);
3454
+ if (root === void 0) return void 0;
3455
+ for (let directory = startDirectory; directory !== root; ) {
3456
+ directory = dirname(directory);
3457
+ if (await gateway.hasConfigFile(directory)) return join2(directory, CONFIG_FILE_NAME);
3458
+ }
3459
+ return void 0;
3460
+ }
3461
+ async function worktreeRoot(gateway, directory) {
3462
+ for (let current = directory; ; current = dirname(current)) {
3463
+ if (await gateway.isWorktreeRoot(current)) return current;
3464
+ if (dirname(current) === current) return void 0;
3465
+ }
3466
+ }
3467
+ async function loadConfig(gateway, startDirectory, definitions, drivers) {
3468
+ const path = await findConfigFile(gateway, startDirectory);
3469
+ if (path === void 0) return { kind: "none" };
3470
+ const imported = await gateway.importConfig(path);
3471
+ switch (imported.kind) {
3472
+ case "import-failed":
3473
+ return {
3474
+ kind: "invalid",
3475
+ path,
3476
+ problems: [{ key: null, location: imported.location ?? null, problem: imported.message }]
3477
+ };
3478
+ case "no-default-export":
3479
+ return {
3480
+ kind: "invalid",
3481
+ path,
3482
+ problems: [fileProblem("has no default export; export default defineConfig({ \u2026 })")]
3483
+ };
3484
+ case "default-export":
3485
+ return checkFile(path, imported.value, definitions, drivers);
3486
+ }
3487
+ }
3488
+ function checkFile(path, value, definitions, drivers) {
3489
+ if (!isRecord5(value))
3490
+ return {
3491
+ kind: "invalid",
3492
+ path,
3493
+ problems: [fileProblem(`must default-export an object, not ${describeValue(value)}`)]
3494
+ };
3495
+ const settings = {};
3496
+ const problems = [];
3497
+ let resources = {};
3498
+ let rawSuites;
3499
+ let hasSuitesKey = false;
3500
+ const settingContext = { drivers };
3501
+ const hasTopLevelDriver = value["driver"] !== void 0;
3502
+ for (const [key, keyValue] of Object.entries(value)) {
3503
+ if (key === "resources") resources = checkResources(keyValue, definitions, problems, "resources");
3504
+ else if (key === "suites") {
3505
+ hasSuitesKey = true;
3506
+ rawSuites = keyValue;
3507
+ } else if (isConfigSettingKey(key)) {
3508
+ if (keyValue !== void 0) checkSetting(key, keyValue, settings, settingContext, problems);
3509
+ } else problems.push({ key, location: null, problem: `is not a ${CONFIG_FILE_NAME} key` });
3510
+ }
3511
+ if (settings.args !== void 0 && !hasTopLevelDriver) {
3512
+ problems.push({ key: "args", location: null, problem: "requires a top-level driver" });
3513
+ }
3514
+ const suites = hasSuitesKey ? checkSuites(
3515
+ rawSuites,
3516
+ {
3517
+ definitions,
3518
+ drivers,
3519
+ hasTopLevelDriver,
3520
+ topLevelRunnerOptions: rawVercelSandboxOptions(value["runner"])
3521
+ },
3522
+ problems
3523
+ ) : {};
3524
+ if (problems.length > 0) return { kind: "invalid", path, problems };
3525
+ return { kind: "loaded", path, values: { settings, resources, suites } };
3526
+ }
3527
+ function checkSetting(key, value, settings, context, problems) {
3528
+ const checked = checkSettingValue(key, value, context);
3529
+ if (checked.ok) Object.assign(settings, { [key]: checked.value });
3530
+ else
3531
+ for (const { path: inside, problem } of checked.problems)
3532
+ problems.push({ key: [key, ...inside].join("."), location: null, problem });
3533
+ }
3534
+ function isRecord5(value) {
2629
3535
  return typeof value === "object" && value !== null && !Array.isArray(value);
2630
3536
  }
2631
3537
  function fileProblem(problem) {
@@ -2739,6 +3645,8 @@ function resolveSettings(flags, file) {
2739
3645
  return {
2740
3646
  scope: pick(flags.scope, file?.scope),
2741
3647
  project: pick(flags.project, file?.project),
3648
+ driver: pick(void 0, file?.driver),
3649
+ args: pick(void 0, file?.args),
2742
3650
  runner: pick(void 0, file?.runner),
2743
3651
  testPlan: pick(void 0, file?.testPlan)
2744
3652
  };
@@ -2823,7 +3731,7 @@ function planResources(resources, run) {
2823
3731
  const merged = settingsFor(run);
2824
3732
  const settings = merged;
2825
3733
  planned.push(...plannedOptions(definition, key, settings));
2826
- const refused2 = definition.check(merged);
3734
+ const refused2 = definition.check(merged, run);
2827
3735
  if (refused2.length === 0)
2828
3736
  resolved[key] = {
2829
3737
  definition: definition.name,
@@ -2876,11 +3784,37 @@ function plannedOptions(definition, key, settings) {
2876
3784
  }
2877
3785
 
2878
3786
  // src/config/settings-file.ts
2879
- async function loadSettingsFile(gateway, cwd, definitions) {
2880
- const loaded = await loadConfig(gateway, cwd, definitions);
3787
+ async function loadSettingsFile(gateway, cwd, definitions, drivers) {
3788
+ const loaded = await loadConfig(gateway, cwd, definitions, drivers);
2881
3789
  if (loaded.kind === "invalid") return refused(invalidConfig(loaded.path, loaded.problems));
2882
3790
  return loaded.kind === "loaded" ? { ok: true, path: loaded.path, values: loaded.values, definitions } : { ok: true, path: null, values: void 0, definitions };
2883
3791
  }
3792
+ function effectiveConfig(file, suite) {
3793
+ if (suite === null || file.values === void 0 || !Object.hasOwn(file.values.suites, suite)) return file;
3794
+ const suiteConfig = file.values.suites[suite];
3795
+ if (suiteConfig === void 0) return file;
3796
+ const resourceEntries = Object.entries(suiteConfig.resources);
3797
+ if (suiteConfig.runner === void 0 && resourceEntries.length === 0) return file;
3798
+ const baseResources = file.values.resources;
3799
+ let resources = baseResources;
3800
+ if (resourceEntries.length > 0) {
3801
+ const merged = { ...baseResources };
3802
+ for (const [key, suiteResource] of resourceEntries) {
3803
+ const top = baseResources[key];
3804
+ merged[key] = top !== void 0 && top.definition === suiteResource.definition ? { definition: suiteResource.definition, options: { ...top.options, ...suiteResource.options } } : { definition: suiteResource.definition, options: { ...suiteResource.options } };
3805
+ }
3806
+ resources = merged;
3807
+ }
3808
+ const settings = suiteConfig.runner === void 0 ? file.values.settings : { ...file.values.settings, runner: suiteConfig.runner };
3809
+ return {
3810
+ ...file,
3811
+ values: {
3812
+ settings,
3813
+ suites: file.values.suites,
3814
+ resources
3815
+ }
3816
+ };
3817
+ }
2884
3818
  function fileSettings(file, flags) {
2885
3819
  return resolveSettings(flags, file.values?.settings);
2886
3820
  }
@@ -3106,7 +4040,7 @@ function runVercel(args) {
3106
4040
  args,
3107
4041
  {
3108
4042
  cwd: tmpdir(),
3109
- env: { ...process.env, NO_COLOR: "1", NO_UPDATE_NOTIFIER: "1" },
4043
+ env: vercelEnvironment(process.env),
3110
4044
  timeout: VERCEL_TIMEOUT_MS,
3111
4045
  maxBuffer: 16 * 1024 * 1024,
3112
4046
  encoding: "utf8"
@@ -3120,6 +4054,11 @@ function runVercel(args) {
3120
4054
  }
3121
4055
  });
3122
4056
  }
4057
+ function vercelEnvironment(host) {
4058
+ const env = { ...host, NO_COLOR: "1", NO_UPDATE_NOTIFIER: "1" };
4059
+ delete env["VERCEL_TOKEN"];
4060
+ return env;
4061
+ }
3123
4062
  function failedRun(error, stdout, stderr) {
3124
4063
  const fields = typeof error === "object" && error !== null ? error : {};
3125
4064
  const out = typeof stdout === "string" ? stdout : "";
@@ -3169,7 +4108,7 @@ function githubActionsSource(context) {
3169
4108
  let inFlight;
3170
4109
  const request2 = async () => {
3171
4110
  await context.progress.emit({ kind: "requesting-token" });
3172
- for (let attempt = 1; ; attempt += 1) {
4111
+ for (let attempt2 = 1; ; attempt2 += 1) {
3173
4112
  const sentAt = context.clock.now().getTime();
3174
4113
  const outcome = await context.gateway.request();
3175
4114
  if (outcome.ok) {
@@ -3178,11 +4117,11 @@ function githubActionsSource(context) {
3178
4117
  }
3179
4118
  const { failure } = outcome;
3180
4119
  if (failure.kind === "variables-missing") return { ok: false, failure: { source: "github-actions", failure } };
3181
- const wait = RETRY_WAITS_MS[attempt - 1];
4120
+ const wait = RETRY_WAITS_MS[attempt2 - 1];
3182
4121
  if (wait === void 0 || !isRetryable(failure))
3183
4122
  return {
3184
4123
  ok: false,
3185
- failure: { source: "github-actions", failure: { kind: "request-failed", attempts: attempt, last: failure } }
4124
+ failure: { source: "github-actions", failure: { kind: "request-failed", attempts: attempt2, last: failure } }
3186
4125
  };
3187
4126
  await context.timer.sleep(wait);
3188
4127
  }
@@ -3322,10 +4261,36 @@ function errorLocation(error, name) {
3322
4261
  return void 0;
3323
4262
  }
3324
4263
 
4264
+ // src/config/live/file-lists-file-gateway.ts
4265
+ import { readFile as readFile2 } from "node:fs/promises";
4266
+ async function readStream(stream) {
4267
+ const chunks = [];
4268
+ for await (const chunk of stream) chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
4269
+ return Buffer.concat(chunks).toString("utf8");
4270
+ }
4271
+ function liveFileListsFileGateway(stdin = process.stdin) {
4272
+ return {
4273
+ readFileListsFile: async ({ path }) => {
4274
+ let text;
4275
+ try {
4276
+ text = path === "-" ? await readStream(stdin) : await readFile2(path, "utf8");
4277
+ } catch (error) {
4278
+ return { kind: "unreadable", message: error instanceof Error ? error.message : String(error) };
4279
+ }
4280
+ try {
4281
+ return { kind: "read", value: JSON.parse(text) };
4282
+ } catch (error) {
4283
+ return { kind: "not-json", message: error instanceof Error ? error.message : String(error) };
4284
+ }
4285
+ }
4286
+ };
4287
+ }
4288
+
3325
4289
  // src/config/recipe-run.ts
3326
4290
  var NOT_PRESENT = Object.freeze({ present: false });
3327
- function recipeRun(resources) {
4291
+ function recipeRun(resources, sandboxes = 1) {
3328
4292
  const run = {
4293
+ sandboxes,
3329
4294
  get: ({ definition }) => {
3330
4295
  const key = defaultResourceKey(definition);
3331
4296
  const resource = Object.hasOwn(resources, key) ? resources[key] : void 0;
@@ -3341,9 +4306,11 @@ function recipeRun(resources) {
3341
4306
 
3342
4307
  // src/config/resolver.ts
3343
4308
  function configResolver(launcher) {
4309
+ const loadFile = () => loadSettingsFile(launcher.gateway, launcher.cwd, launcher.definitions, launcher.drivers);
3344
4310
  return {
4311
+ loadFile,
3345
4312
  async load(definition, options, target) {
3346
- const file = await loadSettingsFile(launcher.gateway, launcher.cwd, launcher.definitions);
4313
+ const file = await loadFile();
3347
4314
  if (!file.ok) return file;
3348
4315
  const settings = fileSettings(file, target);
3349
4316
  const key = defaultResourceKey(definition);
@@ -3370,9 +4337,6 @@ export {
3370
4337
  credentialSourceErrors,
3371
4338
  credentialResolver,
3372
4339
  configErrors,
3373
- RUNNER_SECRET_MIN_LENGTH,
3374
- declaredSecretValues,
3375
- readRunnerSecrets,
3376
4340
  RUNNER_SNAPSHOTS_SUBPATH,
3377
4341
  parseKeepTime,
3378
4342
  systemTimer,
@@ -3381,6 +4345,8 @@ export {
3381
4345
  testEventLine,
3382
4346
  parseTestEvent,
3383
4347
  redactSecrets,
4348
+ MAX_RUNNER_SANDBOXES,
4349
+ resolveSandboxCountDefault,
3384
4350
  lineSplitter,
3385
4351
  prepareSnapshotBuild,
3386
4352
  buildSnapshots,
@@ -3391,14 +4357,19 @@ export {
3391
4357
  liveRunnerSnapshotCacheGateway,
3392
4358
  unavailableRunnerSnapshotCacheGateway,
3393
4359
  prepareRunner,
4360
+ chooseSnapshotForRun,
3394
4361
  SANDBOX_TEST_EVENTS_PATH,
4362
+ declaredSecretValues,
4363
+ readCredentials,
4364
+ readUnsafeSecretEnvVars,
3395
4365
  openRunnerSession,
3396
4366
  inspectSnapshotCache,
3397
4367
  CONFIG_FILE_NAME,
3398
4368
  liveConfigGateway,
4369
+ liveFileListsFileGateway,
3399
4370
  findConfigFile,
3400
4371
  recipeRun,
3401
- loadSettingsFile,
4372
+ effectiveConfig,
3402
4373
  fileSettings,
3403
4374
  settleRunResources,
3404
4375
  invalidConfig,