@cnc-tools/storm 0.16.0 → 0.18.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 (290) hide show
  1. package/dist/bin/storm.js +54 -40
  2. package/dist/build-info.js +1 -1
  3. package/dist/chunks/{chunk-VL7WFTVQ.js → chunk-24UYAK4R.js} +465 -365
  4. package/dist/chunks/{chunk-DC2CDHNK.js → chunk-2JMWUKH3.js} +2074 -473
  5. package/dist/chunks/{chunk-FOZWA52V.js → chunk-3VXZONGE.js} +481 -376
  6. package/dist/chunks/{chunk-ZG3WQ4UF.js → chunk-55O4FCN4.js} +1 -1
  7. package/dist/chunks/{chunk-CN4EFA5J.js → chunk-72ZFEMAW.js} +1 -1
  8. package/dist/chunks/chunk-AS37D43E.js +2173 -0
  9. package/dist/chunks/chunk-CQAY6GLP.js +1260 -0
  10. package/dist/chunks/chunk-DZLU7BYK.js +340 -0
  11. package/dist/chunks/{chunk-R7XVBZOY.js → chunk-EEENLQHE.js} +59 -11
  12. package/dist/chunks/{chunk-TJNFVNKR.js → chunk-EI3XDCEI.js} +1 -1
  13. package/dist/chunks/{chunk-HVNK3I45.js → chunk-FDUY3BNF.js} +1 -1
  14. package/dist/chunks/{chunk-FCQUJDA4.js → chunk-GUCCYCIO.js} +4 -189
  15. package/dist/chunks/{chunk-OIY3DMF2.js → chunk-HBI4LEMH.js} +3 -3
  16. package/dist/chunks/{chunk-2MAD5NKK.js → chunk-K4MDQPLW.js} +1 -18
  17. package/dist/chunks/chunk-KK7PAWIZ.js +198 -0
  18. package/dist/chunks/{chunk-G3PHMXH5.js → chunk-KQ5FXRUD.js} +18 -1
  19. package/dist/chunks/{chunk-5VXBKPW6.js → chunk-LKXHGGGX.js} +1 -1
  20. package/dist/chunks/{chunk-P357TZAY.js → chunk-LOGHIUUB.js} +21 -18
  21. package/dist/chunks/{chunk-CK2GZEPK.js → chunk-OEPFINFT.js} +2 -2
  22. package/dist/chunks/{chunk-DWEAHX4T.js → chunk-OI4AP6Z7.js} +5 -5
  23. package/dist/chunks/{chunk-V4IKA3WI.js → chunk-PMBQWVTW.js} +26 -19
  24. package/dist/chunks/chunk-SZMYIIG2.js +88 -0
  25. package/dist/chunks/{chunk-5CCP36QQ.js → chunk-TXCOFC7N.js} +1 -1
  26. package/dist/chunks/{chunk-VUPZH7J2.js → chunk-UXD3TVWM.js} +1 -1
  27. package/dist/chunks/{chunk-3L52KNQA.js → chunk-WNW2QXQK.js} +8 -8
  28. package/dist/chunks/{chunk-AWBSONHB.js → chunk-XBDRVFEV.js} +55 -16
  29. package/dist/chunks/{live-app-WECQOQ4C.js → live-app-UY7BEDUN.js} +17 -13
  30. package/dist/cli.d.ts +28 -0
  31. package/dist/cli.js +64 -0
  32. package/dist/commands/exec/across-sandboxes-outcomes.d.ts +2 -2
  33. package/dist/commands/exec/across-sandboxes-outcomes.js +3 -3
  34. package/dist/commands/exec/before-run.d.ts +123 -0
  35. package/dist/commands/exec/before-run.js +105 -0
  36. package/dist/commands/exec/command.d.ts +67 -14
  37. package/dist/commands/exec/command.js +31 -95
  38. package/dist/commands/exec/driver-plan.d.ts +9 -4
  39. package/dist/commands/exec/driver-plan.js +8 -8
  40. package/dist/commands/exec/exec-words.js +1 -1
  41. package/dist/commands/exec/execute-run.d.ts +39 -0
  42. package/dist/commands/exec/execute-run.js +325 -0
  43. package/dist/commands/exec/live-view.d.ts +3 -3
  44. package/dist/commands/exec/live-view.js +16 -15
  45. package/dist/commands/exec/metadata.js +1 -1
  46. package/dist/commands/exec/mint-failed.d.ts +38 -0
  47. package/dist/commands/exec/mint-failed.js +27 -4
  48. package/dist/commands/exec/outcomes.d.ts +104 -22
  49. package/dist/commands/exec/outcomes.js +73 -26
  50. package/dist/commands/exec/plan-run.d.ts +58 -150
  51. package/dist/commands/exec/plan-run.js +239 -90
  52. package/dist/commands/exec/progress.d.ts +10 -6
  53. package/dist/commands/exec/progress.js +38 -25
  54. package/dist/commands/exec/run-bin.d.ts +11 -11
  55. package/dist/commands/exec/run-bin.js +9 -9
  56. package/dist/commands/exec/run-flags.d.ts +69 -0
  57. package/dist/commands/exec/run-flags.js +58 -0
  58. package/dist/commands/exec/run-metadata.js +4 -4
  59. package/dist/commands/exec/run-summary.d.ts +58 -0
  60. package/dist/commands/exec/run-summary.js +205 -0
  61. package/dist/commands/exec/runner-refusals.d.ts +82 -0
  62. package/dist/commands/exec/runner-refusals.js +71 -0
  63. package/dist/commands/exec/sandbox-progress.js +3 -0
  64. package/dist/commands/exec/stopped-outcome.d.ts +12 -0
  65. package/dist/commands/exec/stopped-outcome.js +77 -0
  66. package/dist/commands/exec/view.d.ts +20 -11
  67. package/dist/commands/exec/view.js +103 -47
  68. package/dist/commands/runs/facts.d.ts +8 -4
  69. package/dist/commands/runs/facts.js +19 -10
  70. package/dist/commands/runs/list/command.d.ts +16 -8
  71. package/dist/commands/runs/list/command.js +10 -10
  72. package/dist/commands/runs/list/outcomes.d.ts +8 -4
  73. package/dist/commands/runs/logs/command.js +10 -10
  74. package/dist/commands/runs/show/command.d.ts +16 -8
  75. package/dist/commands/runs/show/command.js +31 -29
  76. package/dist/commands/runs/show/metadata.js +1 -1
  77. package/dist/commands/runs/show/outcomes.d.ts +8 -4
  78. package/dist/commands/runs/show/outcomes.js +8 -6
  79. package/dist/commands/snapshots/access.d.ts +111 -0
  80. package/dist/commands/snapshots/access.js +96 -0
  81. package/dist/commands/snapshots/build/command.d.ts +376 -101
  82. package/dist/commands/snapshots/build/command.js +447 -149
  83. package/dist/commands/snapshots/build/metadata.d.ts +10 -0
  84. package/dist/commands/snapshots/build/metadata.js +31 -11
  85. package/dist/commands/snapshots/build/outcomes.d.ts +242 -47
  86. package/dist/commands/snapshots/build/outcomes.js +200 -36
  87. package/dist/commands/snapshots/list/command.d.ts +368 -27
  88. package/dist/commands/snapshots/list/command.js +298 -68
  89. package/dist/commands/snapshots/list/metadata.d.ts +16 -0
  90. package/dist/commands/snapshots/list/metadata.js +29 -6
  91. package/dist/commands/snapshots/list/outcomes.d.ts +247 -15
  92. package/dist/commands/snapshots/list/outcomes.js +223 -52
  93. package/dist/commands/snapshots/metadata.js +1 -1
  94. package/dist/commands/snapshots/prune/command.d.ts +430 -0
  95. package/dist/commands/snapshots/prune/command.js +161 -0
  96. package/dist/commands/snapshots/prune/metadata.d.ts +28 -0
  97. package/dist/commands/snapshots/prune/metadata.js +39 -0
  98. package/dist/commands/snapshots/prune/outcomes.d.ts +208 -0
  99. package/dist/commands/snapshots/prune/outcomes.js +78 -0
  100. package/dist/commands/suites/list/command.js +17 -17
  101. package/dist/commands/suites/list/outcomes.js +2 -2
  102. package/dist/commands/test/command.d.ts +67 -14
  103. package/dist/commands/test/command.js +49 -252
  104. package/dist/commands/test/outcomes.d.ts +33 -7
  105. package/dist/config/check-runner.d.ts +3 -3
  106. package/dist/config/check-runner.js +8 -7
  107. package/dist/config/credential-resolver.d.ts +50 -5
  108. package/dist/config/credential-resolver.js +51 -19
  109. package/dist/config/credential-settle.d.ts +6 -2
  110. package/dist/config/credential-settle.js +11 -5
  111. package/dist/config/index.d.ts +2 -2
  112. package/dist/config/index.js +1 -1
  113. package/dist/config/runner.d.ts +5 -5
  114. package/dist/config/runner.js +1 -1
  115. package/dist/config/schema.d.ts +2 -2
  116. package/dist/config/schema.js +1 -1
  117. package/dist/config-file/define.d.ts +1 -1
  118. package/dist/config-file/define.js +1 -1
  119. package/dist/config-file/runner.d.ts +5 -5
  120. package/dist/config-file/toolchain.d.ts +14 -4
  121. package/dist/config-file/toolchain.js +43 -7
  122. package/dist/context.d.ts +10 -6
  123. package/dist/context.js +8 -6
  124. package/dist/core/across-sandboxes.d.ts +7 -6
  125. package/dist/core/across-sandboxes.js +123 -152
  126. package/dist/core/coordinator.d.ts +166 -0
  127. package/dist/core/coordinator.js +233 -0
  128. package/dist/core/events.d.ts +2 -2
  129. package/dist/core/index.d.ts +4 -2
  130. package/dist/core/index.js +1 -1
  131. package/dist/core/outcomes.d.ts +148 -0
  132. package/dist/core/{sandbox-end.js → outcomes.js} +28 -4
  133. package/dist/core/resources.d.ts +31 -53
  134. package/dist/core/resources.js +32 -70
  135. package/dist/core/run-state.d.ts +7 -1
  136. package/dist/core/run-state.js +2 -0
  137. package/dist/core/run.d.ts +32 -236
  138. package/dist/core/run.js +107 -267
  139. package/dist/core/state-directory.d.ts +1 -1
  140. package/dist/core/state-directory.js +2 -2
  141. package/dist/credential/gateways.d.ts +15 -1
  142. package/dist/credential/index.d.ts +4 -3
  143. package/dist/credential/index.js +3 -2
  144. package/dist/credential/live/vercel-cli-gateway.d.ts +1 -1
  145. package/dist/credential/live/vercel-cli-gateway.js +1 -1
  146. package/dist/credential/live/vercel-oidc-token-gateway.d.ts +11 -0
  147. package/dist/credential/live/vercel-oidc-token-gateway.js +16 -0
  148. package/dist/credential/source.d.ts +73 -6
  149. package/dist/credential/source.js +55 -2
  150. package/dist/extension-commands.d.ts +1 -1
  151. package/dist/extension-commands.js +2 -2
  152. package/dist/extensions/testserver/commands/pool/create/command.d.ts +35 -2
  153. package/dist/extensions/testserver/commands/pool/create/command.js +7 -7
  154. package/dist/extensions/testserver/commands/pool/create/metadata.js +5 -5
  155. package/dist/extensions/testserver/commands/pool/create/outcomes.d.ts +17 -1
  156. package/dist/extensions/testserver/commands/pool/list/command.js +4 -4
  157. package/dist/extensions/testserver/credential-facts.d.ts +6 -2
  158. package/dist/extensions/testserver/credential-facts.js +29 -11
  159. package/dist/extensions/testserver/lifecycle.js +7 -1
  160. package/dist/extensions/testserver/limit.d.ts +3 -0
  161. package/dist/extensions/testserver/limit.js +3 -0
  162. package/dist/extensions/testserver/provision.d.ts +8 -1
  163. package/dist/extensions/testserver/provision.js +8 -3
  164. package/dist/extensions/testserver/refusals.d.ts +6 -1
  165. package/dist/extensions/testserver/refusals.js +16 -1
  166. package/dist/extensions/testserver/resource.d.ts +1 -1
  167. package/dist/extensions/testserver/resource.js +1 -1
  168. package/dist/extensions/testserver/result.d.ts +1 -1
  169. package/dist/extensions/testserver/result.js +9 -4
  170. package/dist/planning/driver-file-lists.d.ts +0 -15
  171. package/dist/planning/driver-file-lists.js +2 -21
  172. package/dist/planning/plan-only.d.ts +3 -14
  173. package/dist/planning/plan-only.js +11 -20
  174. package/dist/planning/run-kind-flags.js +2 -2
  175. package/dist/planning/run-plan.d.ts +45 -12
  176. package/dist/planning/run-plan.js +4 -3
  177. package/dist/planning/suites.d.ts +1 -1
  178. package/dist/planning/suites.js +2 -2
  179. package/dist/planning/test-plan.d.ts +9 -0
  180. package/dist/planning/test-plan.js +9 -0
  181. package/dist/run-directory/recording.js +3 -3
  182. package/dist/run-directory/run-record.d.ts +26 -11
  183. package/dist/run-directory/run-record.js +16 -13
  184. package/dist/runner/base.js +1 -1
  185. package/dist/runner/build-snapshots.d.ts +60 -29
  186. package/dist/runner/build-snapshots.js +136 -29
  187. package/dist/runner/context.d.ts +15 -7
  188. package/dist/runner/context.js +19 -6
  189. package/dist/runner/events.d.ts +16 -10
  190. package/dist/runner/gateways.d.ts +122 -23
  191. package/dist/runner/gateways.js +1 -1
  192. package/dist/runner/gh.d.ts +42 -0
  193. package/dist/runner/gh.js +58 -0
  194. package/dist/runner/index.d.ts +13 -8
  195. package/dist/runner/index.js +12 -6
  196. package/dist/runner/live/checkout-gateway.js +7 -0
  197. package/dist/runner/live/gh-output.d.ts +17 -0
  198. package/dist/runner/live/gh-output.js +37 -0
  199. package/dist/runner/live/gh-token-gateway.d.ts +13 -0
  200. package/dist/runner/live/gh-token-gateway.js +51 -0
  201. package/dist/runner/live/sandbox-errors.d.ts +2 -0
  202. package/dist/runner/live/sandbox-errors.js +4 -0
  203. package/dist/runner/live/sandbox-gateway.js +140 -4
  204. package/dist/runner/live/snapshot-index-gateway.d.ts +12 -0
  205. package/dist/runner/live/{snapshot-cache-gateway.js → snapshot-index-gateway.js} +11 -11
  206. package/dist/runner/live/snapshot-records.js +12 -12
  207. package/dist/runner/local-snapshot-index.d.ts +205 -0
  208. package/dist/runner/local-snapshot-index.js +210 -0
  209. package/dist/runner/network-policy.d.ts +6 -6
  210. package/dist/runner/network-policy.js +7 -7
  211. package/dist/runner/policy-writes.d.ts +1 -1
  212. package/dist/runner/policy-writes.js +1 -1
  213. package/dist/runner/prepare.d.ts +14 -14
  214. package/dist/runner/prepare.js +20 -11
  215. package/dist/runner/ready.d.ts +19 -11
  216. package/dist/runner/ready.js +104 -33
  217. package/dist/runner/sandboxed-command.d.ts +3 -3
  218. package/dist/runner/sandboxed-command.js +3 -3
  219. package/dist/runner/scope.d.ts +15 -8
  220. package/dist/runner/scope.js +16 -5
  221. package/dist/runner/secrets.d.ts +41 -18
  222. package/dist/runner/secrets.js +226 -30
  223. package/dist/runner/session.d.ts +8 -8
  224. package/dist/runner/session.js +6 -3
  225. package/dist/runner/shared-snapshot-entry.d.ts +92 -0
  226. package/dist/runner/shared-snapshot-entry.js +168 -0
  227. package/dist/runner/shared-snapshot-list.d.ts +81 -0
  228. package/dist/runner/shared-snapshot-list.js +155 -0
  229. package/dist/runner/shared-snapshot-lookup.d.ts +51 -0
  230. package/dist/runner/shared-snapshot-lookup.js +118 -0
  231. package/dist/runner/shared-snapshot-prune.d.ts +58 -0
  232. package/dist/runner/shared-snapshot-prune.js +133 -0
  233. package/dist/runner/snapshot-build.d.ts +42 -14
  234. package/dist/runner/snapshot-build.js +79 -47
  235. package/dist/runner/snapshot-choice.js +2 -1
  236. package/dist/runner/snapshot-inspect.d.ts +39 -40
  237. package/dist/runner/snapshot-inspect.js +52 -35
  238. package/dist/runner/snapshot-key.d.ts +32 -17
  239. package/dist/runner/snapshot-key.js +43 -18
  240. package/dist/runner/snapshot-source.d.ts +31 -0
  241. package/dist/runner/snapshot-source.js +122 -0
  242. package/dist/runner/steps.d.ts +1 -1
  243. package/dist/runner/steps.js +1 -1
  244. package/dist/runner/{recipe-check.d.ts → vercel-sandbox-check.d.ts} +4 -2
  245. package/dist/runner/{recipe-check.js → vercel-sandbox-check.js} +7 -2
  246. package/dist/runner/{recipe.d.ts → vercel-sandbox-options.d.ts} +59 -28
  247. package/dist/runner/{recipe.js → vercel-sandbox-options.js} +128 -84
  248. package/dist/runner/vercel-sandbox-secrets.d.ts +116 -0
  249. package/dist/runner/{recipe-secrets.js → vercel-sandbox-secrets.js} +159 -26
  250. package/dist/sdk/extension/credential-diagnosis.d.ts +3 -1
  251. package/dist/sdk/extension/credential-diagnosis.js +25 -5
  252. package/dist/sdk/extension/credential-source.d.ts +20 -3
  253. package/dist/sdk/extension/credential-source.js +4 -4
  254. package/dist/sdk/extension/index.d.ts +3 -2
  255. package/dist/sdk/extension/index.js +2 -1
  256. package/dist/sdk/extension/resource-definition.d.ts +1 -1
  257. package/dist/sdk/extension/secret-source.d.ts +1 -1
  258. package/dist/sdk/extension/secret-source.js +1 -1
  259. package/dist/sdk/extension/vercel-oidc-facts.d.ts +20 -0
  260. package/dist/sdk/extension/vercel-oidc-facts.js +20 -0
  261. package/dist/shared/cleanup.d.ts +3 -3
  262. package/dist/shared/cleanup.js +15 -5
  263. package/dist/shared/snapshot-text.d.ts +4 -4
  264. package/dist/shared/snapshot-text.js +11 -11
  265. package/dist/time/duration.js +1 -1
  266. package/package.json +5 -3
  267. package/skills/overview.md +4 -4
  268. package/skills/plan-runs.md +1 -1
  269. package/skills/read-run-output.md +6 -6
  270. package/dist/application.d.ts +0 -21
  271. package/dist/application.js +0 -30
  272. package/dist/chunks/chunk-7EENF73W.js +0 -782
  273. package/dist/chunks/chunk-Z5PBVG3Y.js +0 -2599
  274. package/dist/commands/exec/across-sandboxes-run.d.ts +0 -180
  275. package/dist/commands/exec/across-sandboxes-run.js +0 -339
  276. package/dist/commands/exec/plan-only.d.ts +0 -10
  277. package/dist/commands/exec/plan-only.js +0 -45
  278. package/dist/commands/exec/run-command.d.ts +0 -475
  279. package/dist/commands/exec/run-command.js +0 -603
  280. package/dist/commands/exec/run-planned.d.ts +0 -20
  281. package/dist/commands/exec/run-planned.js +0 -22
  282. package/dist/commands/exec/sandbox-view.d.ts +0 -19
  283. package/dist/commands/exec/sandbox-view.js +0 -72
  284. package/dist/commands/test/plan.d.ts +0 -92
  285. package/dist/commands/test/plan.js +0 -125
  286. package/dist/core/sandbox-end.d.ts +0 -64
  287. package/dist/runner/live/snapshot-cache-gateway.d.ts +0 -12
  288. package/dist/runner/recipe-secrets.d.ts +0 -67
  289. package/dist/runner/snapshot-cache.d.ts +0 -148
  290. package/dist/runner/snapshot-cache.js +0 -126
@@ -1,67 +1,60 @@
1
- import { type CommandError } from "@vercel/clinkr";
2
1
  import type { StormApp } from "../../context.ts";
3
- import type { CredentialSourceChoice } from "../../credential/index.ts";
4
- import { type ResourceFlagOptions, type SettingsFile } from "../../config/index.ts";
5
- import type { RunTestPlan } from "../../sdk/extension/index.ts";
2
+ import { settleCredential, settleRunResources } from "../../config/index.ts";
6
3
  import type { ResourceLifecycles } from "../../core/index.ts";
7
- import type { PlannedSandboxesRun, PlannedWhere } from "../../planning/run-plan.ts";
8
- /**
9
- * A command's part of planning its run: argv, test plan, optional listed test files, and optional planned runner
10
- * sandboxes.
11
- */
12
- export interface PlannedCommand<TTestPlan extends RunTestPlan> {
13
- readonly ok: true;
14
- readonly argv: readonly string[];
15
- readonly testPlan: TTestPlan;
16
- readonly testFiles?: readonly string[];
17
- readonly sandboxes?: PlannedSandboxesRun;
4
+ import type { DriverRefusals } from "../../planning/driver-refusals.ts";
5
+ import type { RunPlan } from "../../planning/run-plan.ts";
6
+ import { type Driver } from "../../sdk/extension/index.ts";
7
+ import { fileListErrors, sandboxesDefaultErrors, sandboxesErrors } from "./across-sandboxes-outcomes.ts";
8
+ import { type DriverPlanRefusal } from "./driver-plan.ts";
9
+ import { canceledBeforeStart, runErrors } from "./outcomes.ts";
10
+ import { type RunPlanRequest } from "./run-flags.ts";
11
+ /** Planning target for `storm exec`: a direct command argument list with no driver. */
12
+ export interface ExecPlanTarget {
13
+ readonly kind: "exec";
14
+ readonly command: readonly string[];
18
15
  }
19
- /**
20
- * What the config file says to a command's part of planning: whether it plans the tests (`testPlan`) and its path.
21
- */
22
- export interface PlannedSettings {
23
- readonly testPlan: boolean;
24
- readonly configFile: string | null;
16
+ /** Planning target for `storm test`: a driver, its combined arguments, test counting, and driver refusal builders. */
17
+ export interface DriverPlanTarget {
18
+ readonly kind: "driver";
19
+ readonly driver: Driver;
20
+ readonly args: readonly string[];
21
+ readonly countTests: boolean;
22
+ readonly errors: DriverRefusals;
25
23
  }
26
- /**
27
- * A command's part of planning its run, once storm knows where the run runs and before it resolves the resources'
28
- * options: the argv, and what the command counted, which the options' defaults get; or a refusal, which ends the run
29
- * there, with the run's secrets hidden. Nothing is minted, acquired or started yet. Once `signal`, the invocation's,
30
- * aborts, it stops what it started as soon as it can; the run then cancels, whatever it answers.
31
- */
32
- export type PlanCommand<TTestPlan extends RunTestPlan, TRefusal> = (where: PlannedWhere, signal: AbortSignal, settings: PlannedSettings) => Promise<PlannedCommand<TTestPlan> | {
24
+ /** What `planRun` plans: either a direct command (`exec`) or a driver run (`driver`). */
25
+ export type PlanTarget = ExecPlanTarget | DriverPlanTarget;
26
+ type SandboxesMaxRefusal = ReturnType<typeof sandboxesErrors.missingSandboxesMax> | ReturnType<typeof sandboxesErrors.sandboxesOverMax>;
27
+ type FileListRefusal = ReturnType<typeof fileListErrors.fileListsUnreadable> | ReturnType<typeof fileListErrors.invalidFileLists> | ReturnType<typeof fileListErrors.fileListsUnlisted>;
28
+ type SandboxesDefaultRefusal = ReturnType<typeof sandboxesDefaultErrors.sandboxesDefaultRefused>;
29
+ type BasePlanRefusal = ReturnType<typeof runErrors.missingRunner> | ReturnType<typeof runErrors.conflictingOptions> | ReturnType<typeof runErrors.credentialsInvalid> | ReturnType<typeof runErrors.keepSandboxUnsafeSecretEnvVars> | ReturnType<typeof runErrors.keepSandboxManagedCredentials> | ReturnType<typeof runErrors.unsafeSecretEnvVarsInvalid> | Extract<ReturnType<typeof settleCredential>, {
30
+ readonly ok: false;
31
+ }>["refusal"] | Extract<ReturnType<typeof settleRunResources>, {
32
+ readonly ok: false;
33
+ }>["refusal"] | ReturnType<typeof canceledBeforeStart> | SandboxesMaxRefusal;
34
+ type ExecPlanRefusal = BasePlanRefusal;
35
+ type DriverPlanTargetRefusal = BasePlanRefusal | DriverPlanRefusal | FileListRefusal | SandboxesDefaultRefusal;
36
+ type PlanRefusal = ExecPlanRefusal | DriverPlanTargetRefusal;
37
+ type PlanOutcome<TRefusal> = {
38
+ readonly ok: true;
39
+ readonly planned: RunPlan;
40
+ readonly lifecycles: ResourceLifecycles;
41
+ } | {
33
42
  readonly ok: false;
34
43
  readonly refusal: TRefusal;
35
- }>;
44
+ };
36
45
  /**
37
- * Where a run runs once its resources' `beforeRun` let it go on: on the launch machine, with the
38
- * credential source it chose when one of the run's resources needs the Vercel credential; or in a runner sandbox, as
39
- * planned, whose one mint the resources share.
46
+ * What is wrong with `--sandboxes` or `--file-lists` for `driver` and the run's arguments `args` (the command line's,
47
+ * then the config file's): a driver without file list support (`Driver.fileLists`) takes neither, and a driver with it
48
+ * checks the arguments (`fileLists.validate`). Undefined without either flag, or when the driver takes them.
40
49
  */
41
- export type RunWhere = {
42
- readonly kind: "unsandboxed";
43
- readonly credential: CredentialSourceChoice | undefined;
44
- } | Extract<PlannedWhere, {
45
- readonly kind: "runner";
46
- }>;
47
- /** What `planRun` and `resourcesBeforeRun` read of a run's request. */
48
- export interface PlanRequest {
49
- readonly given: ResourceFlagOptions;
50
- readonly scope?: string | undefined;
51
- readonly project?: string | undefined;
52
- readonly runner?: "launch-machine" | undefined;
53
- readonly showOutput: boolean;
54
- readonly keepSandbox?: string | undefined;
55
- readonly credential?: CredentialSourceChoice["source"] | undefined;
56
- /** `--sandboxes`, on `storm exec` and `storm test`. */
50
+ export declare function driverSandboxesProblem(driver: Driver, args: readonly string[], asks: {
57
51
  readonly sandboxes?: number | undefined;
58
- /** `--file-lists`, on `storm test`. */
59
52
  readonly fileLists?: string | undefined;
60
- /** The effective config file (with any selected suite's runner and resources laid over the top level). */
61
- readonly settingsFile: SettingsFile;
62
- /** The selected suite's name, or null when running the top level or `storm exec`. */
63
- readonly suite: string | null;
64
- }
53
+ }): {
54
+ readonly kind: "unsupported" | "args";
55
+ readonly flag: "--sandboxes" | "--file-lists";
56
+ readonly problem: string;
57
+ } | undefined;
65
58
  /**
66
59
  * Plans a run before anything is minted, acquired, or started, refusing in this order:
67
60
  *
@@ -75,101 +68,16 @@ export interface PlanRequest {
75
68
  * 4. Merges each resource's options once (`settleRunResources`): a required option nothing gives is
76
69
  * `invalid_resource_options`. The merged options, each function default given `NOT_COUNTED`, name each resource's
77
70
  * secrets.
78
- * 5. Asks the command for its part (`planCommand`), with the file's `testPlan`: its argv, and what it counted, or its
79
- * refusal, with the credentials' values and the resources' secrets hidden, from each resource's pure `secrets` over
80
- * the merged options. A signal by then cancels the run (`canceledBeforeStart`).
71
+ * 5. Plans the target (`exec` or `driver`), reading `--file-lists` (`file_lists_unreadable`, `invalid_file_lists`)
72
+ * before checking `runner.sandboxes.max` (`missing_sandboxes_max`, `sandboxes_over_max`), running the driver's plan
73
+ * step when needed, and dealing file lists or applying `runner.sandboxes.default`. Any refusal from target planning
74
+ * hides runner secrets and each resource's pure `secrets` over the merged options. A signal by then cancels the run
75
+ * (`canceledBeforeStart`).
81
76
  * 6. Plans the merged options for the planned run (`plan`), each function default given the planned run once, and runs
82
- * the checks across them: `invalid_resource_options`.
83
- */
84
- export declare function planRun<TTestPlan extends RunTestPlan, TRefusal extends CommandError>(app: StormApp, lifecycles: ResourceLifecycles, request: PlanRequest, planCommand: PlanCommand<TTestPlan, TRefusal>, signal: AbortSignal): Promise<{
85
- readonly ok: false;
86
- readonly refusal: CommandError<"invalid_resource_options">;
87
- } | {
88
- readonly ok: false;
89
- readonly refusal: CommandError<"missing_target">;
90
- } | {
91
- readonly ok: false;
92
- readonly refusal: TRefusal;
93
- } | {
94
- readonly ok: false;
95
- readonly refusal: import("@vercel/clinkr").ClinkrError<"canceled">;
96
- } | {
97
- readonly ok: false;
98
- readonly refusal: CommandError<"conflicting_options">;
99
- } | {
100
- readonly ok: false;
101
- readonly refusal: CommandError<"credentials_invalid">;
102
- } | {
103
- readonly ok: false;
104
- readonly refusal: CommandError<"keep_sandbox_unsafe_secret_env_vars">;
105
- } | {
106
- readonly ok: false;
107
- readonly refusal: CommandError<"missing_runner">;
108
- } | {
109
- readonly ok: false;
110
- readonly refusal: CommandError<"unsafe_secret_env_vars_invalid">;
111
- } | {
112
- readonly ok: true;
113
- readonly configFile: string | null;
114
- readonly settings: import("../../config/resolve.ts").ResolvedSettings;
115
- readonly where: PlannedWhere;
116
- readonly argv: readonly string[];
117
- readonly testPlan: TTestPlan;
118
- readonly testFiles: readonly string[] | undefined;
119
- readonly sandboxes: PlannedSandboxesRun | undefined;
120
- readonly resources: {
121
- readonly [key: string]: import("../../config/resolve.ts").ResolvedResourceRecord;
122
- };
123
- readonly planOptions: Readonly<{
124
- path: string;
125
- value: string | number | boolean;
126
- from: "default" | "file" | "flag";
127
- }>[];
128
- }>;
129
- /** A planned run, as `planRun` answers it. */
130
- export type RunPlan = Extract<Awaited<ReturnType<typeof planRun>>, {
131
- readonly ok: true;
132
- }>;
133
- /**
134
- * Calls each resource's `beforeRun` in registry order, with its options and their sources, then chooses the credential
135
- * source, refusing in this order: a resource's `beforeRun` refusal (`resource_refused_before_run`), with the config
136
- * file beside it, which stops the resources after it from being asked; a `--credential` no used resource needs
137
- * (`credential_unused`); in an unsandboxed run, a used resource that needs a runner sandbox
138
- * (`resource_needs_runner_sandbox`, naming every such resource by its key; a skipped resource never refuses); in an
139
- * unsandboxed run where a used resource needs the Vercel credential, the credential source (`missing_target` for the
140
- * mint). Each refusal ends the command before the run starts, so it leaves no run directory.
141
- */
142
- export declare function resourcesBeforeRun(lifecycles: ResourceLifecycles, plan: RunPlan, request: Pick<PlanRequest, "credential">): Promise<{
143
- readonly ok: false;
144
- readonly refusal: CommandError<"missing_target">;
145
- } | {
146
- readonly ok: false;
147
- readonly refusal: CommandError<"credential_unused">;
148
- } | {
149
- readonly ok: false;
150
- readonly refusal: CommandError<"resource_needs_runner_sandbox">;
151
- } | {
152
- readonly ok: false;
153
- readonly refusal: CommandError<"resource_refused_before_run">;
154
- } | {
155
- readonly ok: true;
156
- readonly where: RunWhere;
157
- readonly used: {
158
- readonly ok: true;
159
- readonly requests: import("../../core/resource.ts").ResourceRequests;
160
- readonly skipped: readonly import("../../core/resource.ts").ResourceSkip[];
161
- readonly secrets: readonly string[];
162
- readonly needsVercelCredential: boolean;
163
- readonly needRunnerSandbox: readonly string[];
164
- readonly hiddenVariables: readonly string[];
165
- };
166
- }>;
167
- /** What the resources' `beforeRun` answered, once they let the run go on. */
168
- export type BeforeRun = Extract<Awaited<ReturnType<typeof resourcesBeforeRun>>, {
169
- readonly ok: true;
170
- }>;
171
- /**
172
- * A run canceled before it started, while storm planned it or called its resources' `beforeRun`: nothing was minted,
173
- * acquired or started, and the command didn't run.
77
+ * the checks across them (`invalid_resource_options`), then refuses `--show-output` when `runner.sandboxes.default`
78
+ * made the run across runner sandboxes (`sandboxes_default_refused`).
174
79
  */
175
- export declare function canceledBeforeStart(): import("@vercel/clinkr").ClinkrError<"canceled">;
80
+ export declare function planRun(app: StormApp, request: RunPlanRequest, target: ExecPlanTarget, signal: AbortSignal): Promise<PlanOutcome<ExecPlanRefusal>>;
81
+ export declare function planRun(app: StormApp, request: RunPlanRequest, target: DriverPlanTarget, signal: AbortSignal): Promise<PlanOutcome<DriverPlanTargetRefusal>>;
82
+ export declare function planRun(app: StormApp, request: RunPlanRequest, target: PlanTarget, signal: AbortSignal): Promise<PlanOutcome<PlanRefusal>>;
83
+ export {};
@@ -1,35 +1,74 @@
1
- // Planning a run, which `storm test` and `storm exec` share: settling the runner from the effective config, checking
2
- // unfit flags, running the command's part (`PlanCommand`), resolving each resource's options, then calling the
3
- // resources' `beforeRun` and choosing the credential source. Nothing is minted, acquired, or started yet, and a refusal
1
+ // Planning a run, which `storm test` and `storm exec` share: binding the resources' lifecycles once, settling the
2
+ // runner from the effective config, checking unfit flags and runner requirements, merging each resource's required
3
+ // options, planning the exec or driver target (including `--sandboxes`, `--file-lists`, and `runner.sandboxes.default`),
4
+ // and resolving function defaults and cross-option checks. Nothing is minted, acquired, or started yet, and a refusal
4
5
  // leaves no run directory.
5
6
  import { refused } from "@vercel/clinkr";
6
- import { readCredentials, readUnsafeSecretEnvVars, SECRET_MIN_LENGTH } from "../../runner/index.js";
7
- import { parseKeepTime } from "../../time/index.js";
8
- import { fileSettings, requireTarget, settleCredential, settleRunResources, } from "../../config/index.js";
9
- import { outcomes, runErrors } from "./outcomes.js";
7
+ import { fileSettings, givenTarget, settleCredential, settleRunResources, } from "../../config/index.js";
8
+ import { DEFINITION_SET } from "../../extensions.js";
9
+ import { driverCallerFileListsRun, driverSandboxesRun } from "../../planning/driver-file-lists.js";
10
+ import { readFileListsFile } from "../../planning/file-lists-file.js";
10
11
  import { redactor, redactStrings } from "../../planning/redaction.js";
12
+ import { resourceFlagValues } from "../../planning/resource-flags.js";
11
13
  import { runKindFlagMessage, runKindFlagName, unfitRunFlags } from "../../planning/run-kind-flags.js";
12
- import { resourceRefusedBeforeRun } from "./resource-refusals.js";
14
+ import { commandsForSandboxes } from "../../planning/sandbox-placeholders.js";
15
+ import { readCredentials, readUnsafeSecretEnvVars, resolveSandboxCountDefault, SECRET_MIN_LENGTH, } from "../../runner/index.js";
16
+ import { NOT_COUNTED, } from "../../sdk/extension/index.js";
17
+ import { parseKeepTime } from "../../time/index.js";
18
+ import { fileListErrors, sandboxesDefaultErrors, sandboxesErrors } from "./across-sandboxes-outcomes.js";
19
+ import { driverCount, planDriverCommand } from "./driver-plan.js";
20
+ import { canceledBeforeStart, runErrors } from "./outcomes.js";
21
+ import { SHOW_OUTPUT_ACROSS_SANDBOXES_DETAIL } from "./run-flags.js";
22
+ const SANDBOXES_MAX_KEY = "runner.sandboxes.max";
23
+ const SANDBOXES_DEFAULT_KEY = "runner.sandboxes.default";
13
24
  /**
14
- * Plans a run before anything is minted, acquired, or started, refusing in this order:
15
- *
16
- * 1. Settles the effective runner in one place: `--runner launch-machine` (on `storm exec`), else the effective
17
- * config's `runner`, else `missing_runner`.
18
- * 2. Refuses any flag that doesn't fit the effective runner (`conflicting_options`).
19
- * 3. For the Vercel Sandbox runner, checks the team and project its mint needs (`missing_target`), the credentials'
20
- * values from the launcher environment (`credentials_invalid`), no `--keep-sandbox` above 0 with
21
- * `unsafeSecretEnvVars` (`keep_sandbox_unsafe_secret_env_vars`), and the unsafe secret environment variables' values
22
- * (`unsafe_secret_env_vars_invalid`).
23
- * 4. Merges each resource's options once (`settleRunResources`): a required option nothing gives is
24
- * `invalid_resource_options`. The merged options, each function default given `NOT_COUNTED`, name each resource's
25
- * secrets.
26
- * 5. Asks the command for its part (`planCommand`), with the file's `testPlan`: its argv, and what it counted, or its
27
- * refusal, with the credentials' values and the resources' secrets hidden, from each resource's pure `secrets` over
28
- * the merged options. A signal by then cancels the run (`canceledBeforeStart`).
29
- * 6. Plans the merged options for the planned run (`plan`), each function default given the planned run once, and runs
30
- * the checks across them: `invalid_resource_options`.
25
+ * Checks whether `driver` supports file lists and accepts `args` for a run across runner sandboxes.
31
26
  */
32
- export async function planRun(app, lifecycles, request, planCommand, signal) {
27
+ function checkDriverFileLists(driver, args) {
28
+ if (driver.fileLists === undefined) {
29
+ return {
30
+ ok: false,
31
+ kind: "unsupported",
32
+ problem: `The ${driver.name} driver has no file list support, so storm test can't run it across runner sandboxes.`,
33
+ };
34
+ }
35
+ const checked = driver.fileLists.validate(args);
36
+ return checked.ok ? { ok: true } : { ok: false, kind: "args", problem: checked.problem };
37
+ }
38
+ /**
39
+ * What is wrong with `--sandboxes` or `--file-lists` for `driver` and the run's arguments `args` (the command line's,
40
+ * then the config file's): a driver without file list support (`Driver.fileLists`) takes neither, and a driver with it
41
+ * checks the arguments (`fileLists.validate`). Undefined without either flag, or when the driver takes them.
42
+ */
43
+ export function driverSandboxesProblem(driver, args, asks) {
44
+ const flag = asks.fileLists !== undefined ? "--file-lists" : asks.sandboxes !== undefined ? "--sandboxes" : undefined;
45
+ if (flag === undefined)
46
+ return undefined;
47
+ const checked = checkDriverFileLists(driver, args);
48
+ return checked.ok ? undefined : { kind: checked.kind, flag, problem: checked.problem };
49
+ }
50
+ /**
51
+ * Checks `runner.sandboxes.max` for a run that explicitly asked for runner sandboxes (`--sandboxes` or `--file-lists`).
52
+ */
53
+ function checkSandboxesMax(runner, asked, configFile) {
54
+ if (runner.kind !== "vercel-sandbox")
55
+ throw new Error("a run across runner sandboxes uses the Vercel Sandbox runner");
56
+ const policy = runner.options.sandboxes;
57
+ if (policy === undefined)
58
+ return refused(sandboxesErrors.missingSandboxesMax({ flag: asked.flag, key: SANDBOXES_MAX_KEY, configFile }));
59
+ if (asked.count > policy.max)
60
+ return refused(sandboxesErrors.sandboxesOverMax({
61
+ flag: asked.flag,
62
+ sandboxes: asked.count,
63
+ key: SANDBOXES_MAX_KEY,
64
+ max: policy.max,
65
+ configFile,
66
+ }));
67
+ return { ok: true, runner, max: policy.max };
68
+ }
69
+ export async function planRun(app, request, target, signal) {
70
+ const lifecycles = DEFINITION_SET.lifecycles(app.resourceContexts);
71
+ const given = resourceFlagValues(request);
33
72
  const file = request.settingsFile;
34
73
  const configFile = file.path;
35
74
  const settings = fileSettings(file, request);
@@ -45,60 +84,73 @@ export async function planRun(app, lifecycles, request, planCommand, signal) {
45
84
  configFile,
46
85
  }));
47
86
  }
48
- let where;
87
+ let plannedRunner;
49
88
  if (runner.kind === "launch-machine")
50
- where = { kind: "unsandboxed" };
89
+ plannedRunner = { kind: "launch-machine" };
51
90
  else {
52
91
  // Only a config file declares `vercelSandbox({ … })`, so a run with this runner has one.
53
92
  if (configFile === null)
54
93
  throw new Error("planRun: the Vercel Sandbox runner comes from a config file");
55
- const required = requireTarget(settings.scope, settings.project);
56
- if (!required.ok)
57
- return required;
58
- const { recipe } = runner;
59
- const credentials = readCredentials(recipe, app.env);
94
+ const chosen = settleCredential(request.credential ?? "mint", settings.scope, settings.project);
95
+ if (!chosen.ok)
96
+ return chosen;
97
+ if (chosen.credential.source === "github-actions")
98
+ throw new Error("planRun: --credential github-actions should have been refused for vercel-sandbox");
99
+ const targetConfig = givenTarget(settings.scope, settings.project);
100
+ const { options } = runner;
101
+ const credentials = await readCredentials(options, app.env, app.context);
60
102
  if (!credentials.ok)
61
103
  return refused(runErrors.credentialsInvalid({
62
- variables: credentials.variables.map(({ name, problem }) => ({ name, problem })),
104
+ problems: credentials.problems.map(({ name, problem, detail, hint }) => ({ name, problem, detail, hint })),
63
105
  minLength: SECRET_MIN_LENGTH,
64
106
  configFile,
65
107
  }));
66
108
  const keepFlagMinutes = request.keepSandbox === undefined ? 0 : (parseKeepTime(request.keepSandbox) ?? 0);
67
- if (recipe.unsafeSecretEnvVars.length > 0 && keepFlagMinutes > 0)
109
+ if (options.unsafeSecretEnvVars.length > 0 && keepFlagMinutes > 0)
68
110
  return refused(runErrors.keepSandboxUnsafeSecretEnvVars({
69
- variables: recipe.unsafeSecretEnvVars.map(({ name }) => name),
111
+ variables: options.unsafeSecretEnvVars.map(({ name }) => name),
70
112
  configFile,
71
113
  }));
72
- const unsafeSecretEnvVars = readUnsafeSecretEnvVars(recipe, app.env);
114
+ if (options.managedCredentials.length > 0 && keepFlagMinutes > 0)
115
+ return refused(runErrors.keepSandboxManagedCredentials({
116
+ providers: [...options.managedCredentials],
117
+ configFile,
118
+ }));
119
+ const unsafeSecretEnvVars = readUnsafeSecretEnvVars(options, app.env);
73
120
  if (!unsafeSecretEnvVars.ok)
74
121
  return refused(runErrors.unsafeSecretEnvVarsInvalid({
75
122
  variables: unsafeSecretEnvVars.variables.map(({ name, problem }) => ({ name, problem })),
76
123
  minLength: SECRET_MIN_LENGTH,
77
124
  configFile,
78
125
  }));
79
- where = {
80
- kind: "runner",
126
+ plannedRunner = {
127
+ kind: "vercel-sandbox",
81
128
  configFile,
82
- recipe,
83
- target: required.target,
129
+ options,
130
+ credential: chosen.credential,
131
+ target: targetConfig,
84
132
  credentials: credentials.credentials,
85
133
  unsafeSecretEnvVars: unsafeSecretEnvVars.values,
86
- secrets: [...credentials.credentials.map(({ value }) => value), ...Object.values(unsafeSecretEnvVars.values)],
134
+ secrets: [...credentials.secrets, ...Object.values(unsafeSecretEnvVars.values)],
87
135
  };
88
136
  }
89
137
  // A required option nothing gives is missing whatever the count says, so it refuses before the count. The merged
90
- // options name each resource's secrets, which a refusal from the count hides, even when the checks across a
138
+ // options name each resource's secrets, which a refusal from target planning hides, even when the checks across a
91
139
  // resource's options would refuse it later.
92
- const merged = settleRunResources(file, request.given);
140
+ const merged = settleRunResources(file, given);
93
141
  if (!merged.ok)
94
142
  return merged;
95
- const command = await planCommand(where, signal, { testPlan: settings.testPlan?.value === true, configFile });
143
+ const command = await planTarget(app, request, target, plannedRunner, settings.testPlan?.value === true, configFile, signal);
96
144
  if (signal.aborted)
97
145
  return refused(canceledBeforeStart());
98
146
  if (!command.ok) {
99
- // A refusal can quote what planning ran with this machine's environment, such as the last line of `vitest list`'s
100
- // stderr, which a resource's token can reach. `secrets` is pure, so this calls no `beforeRun`, which may do I/O.
101
- const secrets = [...(where.kind === "runner" ? where.secrets : []), ...lifecycles.secrets(merged.options)];
147
+ // A refusal can quote what planning ran with this machine's environment, such as the last line of a driver's
148
+ // listing stderr, which a resource's token can reach. `secrets` is pure, so this calls no `beforeRun`, which may
149
+ // do I/O.
150
+ const secrets = [
151
+ ...(plannedRunner.kind === "vercel-sandbox" ? plannedRunner.secrets : []),
152
+ ...lifecycles.secrets(merged.options),
153
+ ];
102
154
  return refused(secrets.length === 0 ? command.refusal : redactStrings(command.refusal, redactor(secrets)));
103
155
  }
104
156
  const run = Object.freeze({
@@ -108,58 +160,155 @@ export async function planRun(app, lifecycles, request, planCommand, signal) {
108
160
  const resolved = merged.plan(run);
109
161
  if (!resolved.ok)
110
162
  return resolved;
111
- return {
112
- ok: true,
163
+ if (command.sandboxes?.count.from === "default" && request.showOutput) {
164
+ return refused(sandboxesDefaultErrors.sandboxesDefaultRefused({
165
+ key: SANDBOXES_DEFAULT_KEY,
166
+ sandboxes: command.sandboxes.sandboxes.length,
167
+ field: "showOutput",
168
+ problem: `a run across runner sandboxes ${SHOW_OUTPUT_ACROSS_SANDBOXES_DETAIL}`,
169
+ configFile,
170
+ }));
171
+ }
172
+ const basePlan = {
113
173
  configFile,
114
174
  settings,
115
- where,
116
175
  argv: command.argv,
117
176
  testPlan: command.testPlan,
118
177
  testFiles: command.testFiles,
119
- sandboxes: command.sandboxes,
120
178
  resources: resolved.resources,
121
179
  planOptions: resolved.planned.map(planOption),
122
180
  };
181
+ const planned = command.sandboxes === undefined
182
+ ? { ...basePlan, runner: plannedRunner, sandboxes: undefined }
183
+ : { ...basePlan, runner: command.runner, sandboxes: command.sandboxes };
184
+ return { ok: true, planned, lifecycles };
123
185
  }
124
- /** A planned option as the run's plan names it. */
125
- function planOption({ path, value, source }) {
126
- return { path, value, from: source };
186
+ /** Counts a driver target with file list support and guarantees `testFiles` is present. */
187
+ async function planDriverFiles(app, target, runner, signal) {
188
+ const { driver, args, countTests, errors } = target;
189
+ const planned = await planDriverCommand(app, driver, errors, args, { countTests: driver.countsFilesOnly !== true || countTests }, runner, signal);
190
+ if (!planned.ok)
191
+ return planned;
192
+ const { argv, testPlan, testFiles } = planned;
193
+ if (testFiles === undefined) {
194
+ throw new Error(`planRun: driver ${driver.name} has file list support, and its plan step answered no test files`);
195
+ }
196
+ return { ok: true, argv, testPlan, testFiles };
127
197
  }
128
- /**
129
- * Calls each resource's `beforeRun` in registry order, with its options and their sources, then chooses the credential
130
- * source, refusing in this order: a resource's `beforeRun` refusal (`resource_refused_before_run`), with the config
131
- * file beside it, which stops the resources after it from being asked; a `--credential` no used resource needs
132
- * (`credential_unused`); in an unsandboxed run, a used resource that needs a runner sandbox
133
- * (`resource_needs_runner_sandbox`, naming every such resource by its key; a skipped resource never refuses); in an
134
- * unsandboxed run where a used resource needs the Vercel credential, the credential source (`missing_target` for the
135
- * mint). Each refusal ends the command before the run starts, so it leaves no run directory.
136
- */
137
- export async function resourcesBeforeRun(lifecycles, plan, request) {
138
- const { configFile, resources, settings } = plan;
139
- const used = await lifecycles.beforeRun(resources);
140
- if (!used.ok)
141
- return refused(resourceRefusedBeforeRun(used.resource, used.refusal, configFile));
142
- if (request.credential !== undefined && !used.needsVercelCredential)
143
- return refused(runErrors.credentialUnused({ flags: ["--credential"], configFile }));
144
- if (plan.where.kind !== "runner" && used.needRunnerSandbox.length > 0)
145
- return refused(runErrors.resourceNeedsRunnerSandbox({ resources: [...used.needRunnerSandbox], configFile }));
146
- let where;
147
- if (plan.where.kind === "runner")
148
- where = plan.where;
149
- else if (used.needsVercelCredential) {
150
- const chosen = settleCredential(request.credential ?? "mint", settings.scope, settings.project);
151
- if (!chosen.ok)
152
- return chosen;
153
- where = { kind: "unsandboxed", credential: chosen.credential };
198
+ /** Plans the command or driver target, including `--sandboxes`, `--file-lists`, and `runner.sandboxes.default`. */
199
+ async function planTarget(app, request, target, runner, testPlanSetting, configFile, signal) {
200
+ if (target.kind === "exec") {
201
+ const { command } = target;
202
+ if (request.sandboxes === undefined) {
203
+ return { ok: true, argv: command, testPlan: NOT_COUNTED.testPlan, runner };
204
+ }
205
+ const checked = checkSandboxesMax(runner, { count: request.sandboxes, flag: "--sandboxes" }, configFile);
206
+ if (!checked.ok)
207
+ return checked;
208
+ return {
209
+ ok: true,
210
+ argv: command,
211
+ testPlan: NOT_COUNTED.testPlan,
212
+ runner: checked.runner,
213
+ sandboxes: {
214
+ count: { count: request.sandboxes, from: "flag", max: checked.max },
215
+ sandboxes: commandsForSandboxes(command, request.sandboxes).map((argv) => ({ argv, files: null })),
216
+ },
217
+ };
154
218
  }
155
- else
156
- where = { kind: "unsandboxed", credential: undefined };
157
- return { ok: true, where, used };
219
+ const { driver, args, countTests, errors } = target;
220
+ let lists;
221
+ if (request.fileLists !== undefined) {
222
+ const read = await readFileListsFile(app.context.fileListsFiles, {
223
+ path: request.fileLists,
224
+ cwd: app.cwd,
225
+ sandboxes: request.sandboxes,
226
+ });
227
+ if (!read.ok) {
228
+ return refused(read.kind === "unreadable"
229
+ ? fileListErrors.fileListsUnreadable({ path: read.path, problem: read.problem, message: read.message })
230
+ : fileListErrors.invalidFileLists({
231
+ path: read.path,
232
+ problems: read.problems.map((problem) => problem.kind === "in-two-lists" ? { ...problem, sandboxes: [...problem.sandboxes] } : { ...problem }),
233
+ }));
234
+ }
235
+ lists = read.lists;
236
+ }
237
+ const asked = lists !== undefined
238
+ ? { count: lists.lists.length, flag: "--file-lists" }
239
+ : request.sandboxes === undefined
240
+ ? undefined
241
+ : { count: request.sandboxes, flag: "--sandboxes" };
242
+ if (asked !== undefined) {
243
+ const checked = checkSandboxesMax(runner, asked, configFile);
244
+ if (!checked.ok)
245
+ return checked;
246
+ const planned = await planDriverFiles(app, target, checked.runner, signal);
247
+ if (!planned.ok)
248
+ return planned;
249
+ const { argv, testPlan, testFiles } = planned;
250
+ if (lists === undefined) {
251
+ return {
252
+ ok: true,
253
+ argv,
254
+ testPlan,
255
+ testFiles,
256
+ runner: checked.runner,
257
+ sandboxes: driverSandboxesRun({
258
+ argv,
259
+ testFiles,
260
+ asked: { from: "flag", count: asked.count },
261
+ max: checked.max,
262
+ }),
263
+ };
264
+ }
265
+ const resolved = driverCallerFileListsRun({ argv, testFiles, lists, max: checked.max });
266
+ if (!resolved.ok) {
267
+ return refused(fileListErrors.fileListsUnlisted({
268
+ path: lists.path,
269
+ files: [...resolved.unlisted],
270
+ listed: resolved.listed,
271
+ }));
272
+ }
273
+ return { ok: true, argv, testPlan, testFiles, runner: checked.runner, sandboxes: resolved.sandboxes };
274
+ }
275
+ const policy = runner.kind === "vercel-sandbox" ? runner.options.sandboxes : undefined;
276
+ if (driver.fileLists !== undefined && runner.kind === "vercel-sandbox" && policy?.default !== undefined) {
277
+ const planned = await planDriverFiles(app, target, runner, signal);
278
+ if (!planned.ok)
279
+ return planned;
280
+ const { argv, testPlan, testFiles } = planned;
281
+ const resolved = resolveSandboxCountDefault(policy.default, testPlan);
282
+ const checked = checkDriverFileLists(driver, args);
283
+ if (!checked.ok) {
284
+ return refused(sandboxesDefaultErrors.sandboxesDefaultRefused({
285
+ key: SANDBOXES_DEFAULT_KEY,
286
+ sandboxes: Math.min(resolved, policy.max, testFiles.length),
287
+ field: "args",
288
+ problem: checked.problem,
289
+ configFile,
290
+ }));
291
+ }
292
+ return {
293
+ ok: true,
294
+ argv,
295
+ testPlan,
296
+ testFiles,
297
+ runner,
298
+ sandboxes: driverSandboxesRun({
299
+ argv,
300
+ testFiles,
301
+ asked: { from: "default", default: resolved },
302
+ max: policy.max,
303
+ }),
304
+ };
305
+ }
306
+ const single = await planDriverCommand(app, driver, errors, args, driverCount(driver, testPlanSetting, countTests), runner, signal);
307
+ if (!single.ok)
308
+ return single;
309
+ return { ...single, runner };
158
310
  }
159
- /**
160
- * A run canceled before it started, while storm planned it or called its resources' `beforeRun`: nothing was minted,
161
- * acquired or started, and the command didn't run.
162
- */
163
- export function canceledBeforeStart() {
164
- return outcomes.canceled({ changed: "The command didn't run.\nNothing was minted, acquired or started." });
311
+ /** A planned option as the run's plan names it. */
312
+ function planOption({ path, value, source }) {
313
+ return { path, value, from: source };
165
314
  }