@cnc-tools/storm 0.0.0 → 0.6.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 (527) hide show
  1. package/bin/node-version.js +24 -0
  2. package/bin/storm.js +16 -0
  3. package/dist/application.d.ts +13 -0
  4. package/dist/application.js +23 -0
  5. package/dist/bin/storm.d.ts +1 -0
  6. package/dist/bin/storm.js +45 -0
  7. package/dist/build-info.js +3 -0
  8. package/dist/closed-terminal.d.ts +7 -0
  9. package/dist/closed-terminal.js +18 -0
  10. package/dist/combine-errors.d.ts +11 -0
  11. package/dist/combine-errors.js +19 -0
  12. package/dist/commands/dashboard.d.ts +11 -0
  13. package/dist/commands/dashboard.js +18 -0
  14. package/dist/commands/exec/cleanup.d.ts +135 -0
  15. package/dist/commands/exec/cleanup.js +171 -0
  16. package/dist/commands/exec/command.d.ts +272 -0
  17. package/dist/commands/exec/command.js +23 -0
  18. package/dist/commands/exec/job-summary.d.ts +10 -0
  19. package/dist/commands/exec/job-summary.js +34 -0
  20. package/dist/commands/exec/live-view.d.ts +22 -0
  21. package/dist/commands/exec/live-view.js +395 -0
  22. package/dist/commands/exec/metadata.d.ts +66 -0
  23. package/dist/commands/exec/metadata.js +55 -0
  24. package/dist/commands/exec/mint-failed.d.ts +11 -0
  25. package/dist/commands/exec/mint-failed.js +33 -0
  26. package/dist/commands/exec/outcomes.d.ts +614 -0
  27. package/dist/commands/exec/outcomes.js +338 -0
  28. package/dist/commands/exec/progress.d.ts +44 -0
  29. package/dist/commands/exec/progress.js +277 -0
  30. package/dist/commands/exec/redaction.d.ts +15 -0
  31. package/dist/commands/exec/redaction.js +40 -0
  32. package/dist/commands/exec/run-collector.d.ts +30 -0
  33. package/dist/commands/exec/run-collector.js +73 -0
  34. package/dist/commands/exec/run-command.d.ts +221 -0
  35. package/dist/commands/exec/run-command.js +663 -0
  36. package/dist/commands/exec/run-metadata.d.ts +56 -0
  37. package/dist/commands/exec/run-metadata.js +58 -0
  38. package/dist/commands/exec/run-record.d.ts +170 -0
  39. package/dist/commands/exec/run-record.js +104 -0
  40. package/dist/commands/exec/tests-summary.d.ts +34 -0
  41. package/dist/commands/exec/tests-summary.js +141 -0
  42. package/dist/commands/exec/testserver-flags.d.ts +48 -0
  43. package/dist/commands/exec/testserver-flags.js +80 -0
  44. package/dist/commands/exec/text.d.ts +22 -0
  45. package/dist/commands/exec/text.js +74 -0
  46. package/dist/commands/exec/view.d.ts +35 -0
  47. package/dist/commands/exec/view.js +163 -0
  48. package/dist/commands/exec/waterfall.d.ts +25 -0
  49. package/dist/commands/exec/waterfall.js +108 -0
  50. package/dist/commands/exec/worker-chart.d.ts +79 -0
  51. package/dist/commands/exec/worker-chart.js +313 -0
  52. package/dist/commands/runs/facts.d.ts +150 -0
  53. package/dist/commands/runs/facts.js +292 -0
  54. package/dist/commands/runs/list/command.d.ts +86 -0
  55. package/dist/commands/runs/list/command.js +36 -0
  56. package/dist/commands/runs/list/metadata.d.ts +22 -0
  57. package/dist/commands/runs/list/metadata.js +19 -0
  58. package/dist/commands/runs/list/outcomes.d.ts +74 -0
  59. package/dist/commands/runs/list/outcomes.js +89 -0
  60. package/dist/commands/runs/logs/command.d.ts +72 -0
  61. package/dist/commands/runs/logs/command.js +51 -0
  62. package/dist/commands/runs/logs/metadata.d.ts +22 -0
  63. package/dist/commands/runs/logs/metadata.js +22 -0
  64. package/dist/commands/runs/logs/outcomes.d.ts +55 -0
  65. package/dist/commands/runs/logs/outcomes.js +80 -0
  66. package/dist/commands/runs/metadata.d.ts +3 -0
  67. package/dist/commands/runs/metadata.js +3 -0
  68. package/dist/commands/runs/past-run.d.ts +72 -0
  69. package/dist/commands/runs/past-run.js +99 -0
  70. package/dist/commands/runs/show/command.d.ts +176 -0
  71. package/dist/commands/runs/show/command.js +76 -0
  72. package/dist/commands/runs/show/metadata.d.ts +25 -0
  73. package/dist/commands/runs/show/metadata.js +22 -0
  74. package/dist/commands/runs/show/outcomes.d.ts +164 -0
  75. package/dist/commands/runs/show/outcomes.js +320 -0
  76. package/dist/commands/vitest/command.d.ts +299 -0
  77. package/dist/commands/vitest/command.js +138 -0
  78. package/dist/commands/vitest/metadata.d.ts +66 -0
  79. package/dist/commands/vitest/metadata.js +35 -0
  80. package/dist/commands/vitest/outcomes.d.ts +273 -0
  81. package/dist/commands/vitest/outcomes.js +77 -0
  82. package/dist/config/by-name.d.ts +24 -0
  83. package/dist/config/by-name.js +26 -0
  84. package/dist/config/errors.d.ts +58 -0
  85. package/dist/config/errors.js +101 -0
  86. package/dist/config/gateways.d.ts +32 -0
  87. package/dist/config/gateways.js +1 -0
  88. package/dist/config/index.d.ts +10 -0
  89. package/dist/config/index.js +13 -0
  90. package/dist/config/live/config-gateway.d.ts +6 -0
  91. package/dist/config/live/config-gateway.js +71 -0
  92. package/dist/config/load.d.ts +54 -0
  93. package/dist/config/load.js +175 -0
  94. package/dist/config/resolve.d.ts +49 -0
  95. package/dist/config/resolve.js +94 -0
  96. package/dist/config/resource-config.d.ts +132 -0
  97. package/dist/config/resource-config.js +19 -0
  98. package/dist/config/schema.d.ts +64 -0
  99. package/dist/config/schema.js +57 -0
  100. package/dist/config/set.d.ts +27 -0
  101. package/dist/config/set.js +71 -0
  102. package/dist/config/settings-file.d.ts +41 -0
  103. package/dist/config/settings-file.js +72 -0
  104. package/dist/config-file/define.d.ts +39 -0
  105. package/dist/config-file/define.js +9 -0
  106. package/dist/config-file/toolchain.d.ts +9 -0
  107. package/dist/config-file/toolchain.js +41 -0
  108. package/dist/context.d.ts +89 -0
  109. package/dist/context.js +45 -0
  110. package/dist/core/command-provider.d.ts +126 -0
  111. package/dist/core/command-provider.js +13 -0
  112. package/dist/core/command-slots.d.ts +67 -0
  113. package/dist/core/command-slots.js +136 -0
  114. package/dist/core/events.d.ts +128 -0
  115. package/dist/core/events.js +15 -0
  116. package/dist/core/gateways.d.ts +249 -0
  117. package/dist/core/gateways.js +1 -0
  118. package/dist/core/index.d.ts +20 -0
  119. package/dist/core/index.js +18 -0
  120. package/dist/core/keyed.d.ts +12 -0
  121. package/dist/core/keyed.js +24 -0
  122. package/dist/core/lane.d.ts +46 -0
  123. package/dist/core/lane.js +5 -0
  124. package/dist/core/limit.d.ts +9 -0
  125. package/dist/core/limit.js +29 -0
  126. package/dist/core/live/command-gateway.d.ts +11 -0
  127. package/dist/core/live/command-gateway.js +83 -0
  128. package/dist/core/live/job-summary-gateway.d.ts +5 -0
  129. package/dist/core/live/job-summary-gateway.js +20 -0
  130. package/dist/core/live/progress-terminal.d.ts +20 -0
  131. package/dist/core/live/progress-terminal.js +173 -0
  132. package/dist/core/live/run-directory-gateway.d.ts +24 -0
  133. package/dist/core/live/run-directory-gateway.js +437 -0
  134. package/dist/core/mint.d.ts +10 -0
  135. package/dist/core/mint.js +14 -0
  136. package/dist/core/payload.d.ts +26 -0
  137. package/dist/core/payload.js +33 -0
  138. package/dist/core/presentation.d.ts +87 -0
  139. package/dist/core/presentation.js +5 -0
  140. package/dist/core/presentations.d.ts +56 -0
  141. package/dist/core/presentations.js +66 -0
  142. package/dist/core/provider.d.ts +69 -0
  143. package/dist/core/provider.js +5 -0
  144. package/dist/core/resource.d.ts +262 -0
  145. package/dist/core/resource.js +6 -0
  146. package/dist/core/resources.d.ts +131 -0
  147. package/dist/core/resources.js +254 -0
  148. package/dist/core/run-directory.d.ts +69 -0
  149. package/dist/core/run-directory.js +94 -0
  150. package/dist/core/run-state.d.ts +152 -0
  151. package/dist/core/run-state.js +313 -0
  152. package/dist/core/run.d.ts +187 -0
  153. package/dist/core/run.js +321 -0
  154. package/dist/core/state-directory.d.ts +19 -0
  155. package/dist/core/state-directory.js +29 -0
  156. package/dist/core/timeline.d.ts +63 -0
  157. package/dist/core/timeline.js +97 -0
  158. package/dist/core/timing.d.ts +22 -0
  159. package/dist/core/timing.js +26 -0
  160. package/dist/credential/credential.d.ts +46 -0
  161. package/dist/credential/credential.js +80 -0
  162. package/dist/credential/diagnosis.d.ts +18 -0
  163. package/dist/credential/diagnosis.js +99 -0
  164. package/dist/credential/gateways.d.ts +109 -0
  165. package/dist/credential/gateways.js +1 -0
  166. package/dist/credential/index.d.ts +7 -0
  167. package/dist/credential/index.js +7 -0
  168. package/dist/credential/live/github-actions-token-gateway.d.ts +15 -0
  169. package/dist/credential/live/github-actions-token-gateway.js +43 -0
  170. package/dist/credential/live/github-actions-token-response.d.ts +19 -0
  171. package/dist/credential/live/github-actions-token-response.js +49 -0
  172. package/dist/credential/live/vercel-cli-gateway.d.ts +9 -0
  173. package/dist/credential/live/vercel-cli-gateway.js +64 -0
  174. package/dist/credential/live/vercel-output.d.ts +60 -0
  175. package/dist/credential/live/vercel-output.js +122 -0
  176. package/dist/credential/live/vercel-process.d.ts +14 -0
  177. package/dist/credential/live/vercel-process.js +3 -0
  178. package/dist/credential/settle.d.ts +31 -0
  179. package/dist/credential/settle.js +49 -0
  180. package/dist/credential/source.d.ts +110 -0
  181. package/dist/credential/source.js +114 -0
  182. package/dist/help-logo.d.ts +11 -0
  183. package/dist/help-logo.js +56 -0
  184. package/dist/presentation.d.ts +26 -0
  185. package/dist/presentation.js +21 -0
  186. package/dist/resources/github/cleanup.d.ts +23 -0
  187. package/dist/resources/github/cleanup.js +39 -0
  188. package/dist/resources/github/command.d.ts +74 -0
  189. package/dist/resources/github/command.js +117 -0
  190. package/dist/resources/github/config.d.ts +16 -0
  191. package/dist/resources/github/config.js +37 -0
  192. package/dist/resources/github/events.d.ts +26 -0
  193. package/dist/resources/github/events.js +2 -0
  194. package/dist/resources/github/fixture-repo.d.ts +69 -0
  195. package/dist/resources/github/fixture-repo.js +60 -0
  196. package/dist/resources/github/gateways.d.ts +62 -0
  197. package/dist/resources/github/gateways.js +1 -0
  198. package/dist/resources/github/index.d.ts +12 -0
  199. package/dist/resources/github/index.js +15 -0
  200. package/dist/resources/github/live/fixture-repo-gateway.d.ts +12 -0
  201. package/dist/resources/github/live/fixture-repo-gateway.js +92 -0
  202. package/dist/resources/github/live/gateways.d.ts +6 -0
  203. package/dist/resources/github/live/gateways.js +13 -0
  204. package/dist/resources/github/presentation.d.ts +13 -0
  205. package/dist/resources/github/presentation.js +43 -0
  206. package/dist/resources/github/provider.d.ts +66 -0
  207. package/dist/resources/github/provider.js +58 -0
  208. package/dist/resources/github/resource-provider.d.ts +6 -0
  209. package/dist/resources/github/resource-provider.js +20 -0
  210. package/dist/resources/github/resource.d.ts +33 -0
  211. package/dist/resources/github/resource.js +12 -0
  212. package/dist/resources/testserver/cleanup.d.ts +14 -0
  213. package/dist/resources/testserver/cleanup.js +22 -0
  214. package/dist/resources/testserver/command.d.ts +322 -0
  215. package/dist/resources/testserver/command.js +245 -0
  216. package/dist/resources/testserver/commands/app.d.ts +18 -0
  217. package/dist/resources/testserver/commands/app.js +3 -0
  218. package/dist/resources/testserver/commands/create/command.d.ts +136 -0
  219. package/dist/resources/testserver/commands/create/command.js +158 -0
  220. package/dist/resources/testserver/commands/create/metadata.d.ts +31 -0
  221. package/dist/resources/testserver/commands/create/metadata.js +45 -0
  222. package/dist/resources/testserver/commands/create/outcomes.d.ts +111 -0
  223. package/dist/resources/testserver/commands/create/outcomes.js +172 -0
  224. package/dist/resources/testserver/commands/list/command.d.ts +60 -0
  225. package/dist/resources/testserver/commands/list/command.js +56 -0
  226. package/dist/resources/testserver/commands/list/metadata.d.ts +9 -0
  227. package/dist/resources/testserver/commands/list/metadata.js +9 -0
  228. package/dist/resources/testserver/commands/list/outcomes.d.ts +54 -0
  229. package/dist/resources/testserver/commands/list/outcomes.js +152 -0
  230. package/dist/resources/testserver/config.d.ts +18 -0
  231. package/dist/resources/testserver/config.js +78 -0
  232. package/dist/resources/testserver/credential-facts.d.ts +80 -0
  233. package/dist/resources/testserver/credential-facts.js +83 -0
  234. package/dist/resources/testserver/events.d.ts +59 -0
  235. package/dist/resources/testserver/events.js +4 -0
  236. package/dist/resources/testserver/index.d.ts +16 -0
  237. package/dist/resources/testserver/index.js +24 -0
  238. package/dist/resources/testserver/lane.d.ts +28 -0
  239. package/dist/resources/testserver/lane.js +139 -0
  240. package/dist/resources/testserver/live/gateways.d.ts +6 -0
  241. package/dist/resources/testserver/live/gateways.js +26 -0
  242. package/dist/resources/testserver/options.d.ts +5 -0
  243. package/dist/resources/testserver/options.js +5 -0
  244. package/dist/resources/testserver/pool/channels.d.ts +80 -0
  245. package/dist/resources/testserver/pool/channels.js +48 -0
  246. package/dist/resources/testserver/pool/create.d.ts +48 -0
  247. package/dist/resources/testserver/pool/create.js +45 -0
  248. package/dist/resources/testserver/pool/directory.d.ts +4 -0
  249. package/dist/resources/testserver/pool/directory.js +5 -0
  250. package/dist/resources/testserver/pool/gateways.d.ts +190 -0
  251. package/dist/resources/testserver/pool/gateways.js +1 -0
  252. package/dist/resources/testserver/pool/host.d.ts +8 -0
  253. package/dist/resources/testserver/pool/host.js +21 -0
  254. package/dist/resources/testserver/pool/index.d.ts +9 -0
  255. package/dist/resources/testserver/pool/index.js +10 -0
  256. package/dist/resources/testserver/pool/inspect.d.ts +53 -0
  257. package/dist/resources/testserver/pool/inspect.js +45 -0
  258. package/dist/resources/testserver/pool/lease.d.ts +84 -0
  259. package/dist/resources/testserver/pool/lease.js +125 -0
  260. package/dist/resources/testserver/pool/live/pool-records.d.ts +17 -0
  261. package/dist/resources/testserver/pool/live/pool-records.js +70 -0
  262. package/dist/resources/testserver/pool/live/pool-store-gateway.d.ts +12 -0
  263. package/dist/resources/testserver/pool/live/pool-store-gateway.js +435 -0
  264. package/dist/resources/testserver/pool/staleness.d.ts +16 -0
  265. package/dist/resources/testserver/pool/staleness.js +27 -0
  266. package/dist/resources/testserver/presentation.d.ts +9 -0
  267. package/dist/resources/testserver/presentation.js +217 -0
  268. package/dist/resources/testserver/provider.d.ts +177 -0
  269. package/dist/resources/testserver/provider.js +254 -0
  270. package/dist/resources/testserver/ran.d.ts +87 -0
  271. package/dist/resources/testserver/ran.js +140 -0
  272. package/dist/resources/testserver/resource-provider.d.ts +12 -0
  273. package/dist/resources/testserver/resource-provider.js +38 -0
  274. package/dist/resources/testserver/resource.d.ts +32 -0
  275. package/dist/resources/testserver/resource.js +10 -0
  276. package/dist/resources/testserver/run-sandbox.d.ts +13 -0
  277. package/dist/resources/testserver/run-sandbox.js +6 -0
  278. package/dist/resources/testserver/sandbox/channels.d.ts +12 -0
  279. package/dist/resources/testserver/sandbox/channels.js +21 -0
  280. package/dist/resources/testserver/sandbox/create-failure.d.ts +35 -0
  281. package/dist/resources/testserver/sandbox/create-failure.js +65 -0
  282. package/dist/resources/testserver/sandbox/create.d.ts +29 -0
  283. package/dist/resources/testserver/sandbox/create.js +37 -0
  284. package/dist/resources/testserver/sandbox/gateways.d.ts +150 -0
  285. package/dist/resources/testserver/sandbox/gateways.js +1 -0
  286. package/dist/resources/testserver/sandbox/index.d.ts +6 -0
  287. package/dist/resources/testserver/sandbox/index.js +7 -0
  288. package/dist/resources/testserver/sandbox/live/builds-response.d.ts +9 -0
  289. package/dist/resources/testserver/sandbox/live/builds-response.js +27 -0
  290. package/dist/resources/testserver/sandbox/live/control-plane-gateway.d.ts +17 -0
  291. package/dist/resources/testserver/sandbox/live/control-plane-gateway.js +133 -0
  292. package/dist/resources/testserver/sandbox/live/create-response.d.ts +35 -0
  293. package/dist/resources/testserver/sandbox/live/create-response.js +78 -0
  294. package/dist/resources/testserver/sandbox/live/fetch-failure.d.ts +24 -0
  295. package/dist/resources/testserver/sandbox/live/fetch-failure.js +45 -0
  296. package/dist/resources/testserver/sandbox/live/health-check-gateway.d.ts +11 -0
  297. package/dist/resources/testserver/sandbox/live/health-check-gateway.js +36 -0
  298. package/dist/resources/testserver/sandbox/live/sse.d.ts +12 -0
  299. package/dist/resources/testserver/sandbox/live/sse.js +32 -0
  300. package/dist/resources.d.ts +455 -0
  301. package/dist/resources.js +88 -0
  302. package/dist/runner/base.d.ts +40 -0
  303. package/dist/runner/base.js +52 -0
  304. package/dist/runner/context.d.ts +13 -0
  305. package/dist/runner/context.js +9 -0
  306. package/dist/runner/events.d.ts +179 -0
  307. package/dist/runner/events.js +16 -0
  308. package/dist/runner/gateways.d.ts +351 -0
  309. package/dist/runner/gateways.js +3 -0
  310. package/dist/runner/index.d.ts +19 -0
  311. package/dist/runner/index.js +18 -0
  312. package/dist/runner/live/checkout-gateway.d.ts +3 -0
  313. package/dist/runner/live/checkout-gateway.js +206 -0
  314. package/dist/runner/live/git-output.d.ts +14 -0
  315. package/dist/runner/live/git-output.js +32 -0
  316. package/dist/runner/live/sandbox-errors.d.ts +7 -0
  317. package/dist/runner/live/sandbox-errors.js +21 -0
  318. package/dist/runner/live/sandbox-gateway.d.ts +7 -0
  319. package/dist/runner/live/sandbox-gateway.js +427 -0
  320. package/dist/runner/live/snapshot-cache-gateway.d.ts +12 -0
  321. package/dist/runner/live/snapshot-cache-gateway.js +104 -0
  322. package/dist/runner/live/snapshot-records.d.ts +11 -0
  323. package/dist/runner/live/snapshot-records.js +57 -0
  324. package/dist/runner/live/terminal.d.ts +16 -0
  325. package/dist/runner/live/terminal.js +37 -0
  326. package/dist/runner/live/user.d.ts +2 -0
  327. package/dist/runner/live/user.js +11 -0
  328. package/dist/runner/output.d.ts +23 -0
  329. package/dist/runner/output.js +58 -0
  330. package/dist/runner/prepare.d.ts +67 -0
  331. package/dist/runner/prepare.js +59 -0
  332. package/dist/runner/ready.d.ts +68 -0
  333. package/dist/runner/ready.js +159 -0
  334. package/dist/runner/recipe.d.ts +126 -0
  335. package/dist/runner/recipe.js +302 -0
  336. package/dist/runner/remote-command.d.ts +77 -0
  337. package/dist/runner/remote-command.js +127 -0
  338. package/dist/runner/scope.d.ts +58 -0
  339. package/dist/runner/scope.js +117 -0
  340. package/dist/runner/snapshot-build.d.ts +33 -0
  341. package/dist/runner/snapshot-build.js +112 -0
  342. package/dist/runner/snapshot-cache.d.ts +84 -0
  343. package/dist/runner/snapshot-cache.js +126 -0
  344. package/dist/runner/snapshot-key.d.ts +52 -0
  345. package/dist/runner/snapshot-key.js +91 -0
  346. package/dist/runner/steps.d.ts +41 -0
  347. package/dist/runner/steps.js +49 -0
  348. package/dist/sdk/container/api-request.d.ts +32 -0
  349. package/dist/sdk/container/api-request.js +46 -0
  350. package/dist/sdk/container/container.d.ts +144 -0
  351. package/dist/sdk/container/container.js +346 -0
  352. package/dist/sdk/container/feature-flags.d.ts +37 -0
  353. package/dist/sdk/container/feature-flags.js +118 -0
  354. package/dist/sdk/container/gateways.d.ts +108 -0
  355. package/dist/sdk/container/gateways.js +1 -0
  356. package/dist/sdk/container/index.d.ts +5 -0
  357. package/dist/sdk/container/index.js +5 -0
  358. package/dist/sdk/container/live/container-gateway.d.ts +17 -0
  359. package/dist/sdk/container/live/container-gateway.js +114 -0
  360. package/dist/sdk/factories/build.d.ts +66 -0
  361. package/dist/sdk/factories/build.js +98 -0
  362. package/dist/sdk/factories/definition.d.ts +28 -0
  363. package/dist/sdk/factories/definition.js +16 -0
  364. package/dist/sdk/factories/definitions.d.ts +166 -0
  365. package/dist/sdk/factories/definitions.js +235 -0
  366. package/dist/sdk/factories/gateways.d.ts +25 -0
  367. package/dist/sdk/factories/gateways.js +1 -0
  368. package/dist/sdk/factories/index.d.ts +5 -0
  369. package/dist/sdk/factories/index.js +5 -0
  370. package/dist/sdk/factories/live/factory-gateway.d.ts +10 -0
  371. package/dist/sdk/factories/live/factory-gateway.js +29 -0
  372. package/dist/sdk/index.d.ts +7 -0
  373. package/dist/sdk/index.js +15 -0
  374. package/dist/sdk/payload/index.d.ts +2 -0
  375. package/dist/sdk/payload/index.js +4 -0
  376. package/dist/sdk/payload/payload.d.ts +47 -0
  377. package/dist/sdk/payload/payload.js +74 -0
  378. package/dist/sdk/payload/test-events.d.ts +102 -0
  379. package/dist/sdk/payload/test-events.js +59 -0
  380. package/dist/sdk/proxy/exchange.d.ts +58 -0
  381. package/dist/sdk/proxy/exchange.js +173 -0
  382. package/dist/sdk/proxy/faulted-exchange.d.ts +10 -0
  383. package/dist/sdk/proxy/faulted-exchange.js +106 -0
  384. package/dist/sdk/proxy/faults.d.ts +133 -0
  385. package/dist/sdk/proxy/faults.js +147 -0
  386. package/dist/sdk/proxy/index.d.ts +3 -0
  387. package/dist/sdk/proxy/index.js +3 -0
  388. package/dist/sdk/proxy/proxy.d.ts +93 -0
  389. package/dist/sdk/proxy/proxy.js +99 -0
  390. package/dist/sdk/proxy/records.d.ts +56 -0
  391. package/dist/sdk/proxy/records.js +56 -0
  392. package/dist/sdk/records/body.d.ts +89 -0
  393. package/dist/sdk/records/body.js +236 -0
  394. package/dist/sdk/records/index.d.ts +2 -0
  395. package/dist/sdk/records/index.js +4 -0
  396. package/dist/sdk/records/records.d.ts +49 -0
  397. package/dist/sdk/records/records.js +16 -0
  398. package/dist/sdk/seed/index.d.ts +1 -0
  399. package/dist/sdk/seed/index.js +3 -0
  400. package/dist/sdk/seed/seed.d.ts +221 -0
  401. package/dist/sdk/seed/seed.js +171 -0
  402. package/dist/sdk/testserver/clock.d.ts +8 -0
  403. package/dist/sdk/testserver/clock.js +10 -0
  404. package/dist/sdk/testserver/failure.d.ts +73 -0
  405. package/dist/sdk/testserver/failure.js +61 -0
  406. package/dist/sdk/testserver/index.d.ts +5 -0
  407. package/dist/sdk/testserver/index.js +8 -0
  408. package/dist/sdk/testserver/live/connect-failure.d.ts +7 -0
  409. package/dist/sdk/testserver/live/connect-failure.js +30 -0
  410. package/dist/sdk/testserver/live/request.d.ts +69 -0
  411. package/dist/sdk/testserver/live/request.js +89 -0
  412. package/dist/sdk/testserver/service-ids.d.ts +19 -0
  413. package/dist/sdk/testserver/service-ids.js +77 -0
  414. package/dist/sdk/testserver/test-id.d.ts +15 -0
  415. package/dist/sdk/testserver/test-id.js +28 -0
  416. package/dist/story/align.d.ts +37 -0
  417. package/dist/story/align.js +39 -0
  418. package/dist/story/artifact.d.ts +60 -0
  419. package/dist/story/artifact.js +93 -0
  420. package/dist/story/definition.d.ts +52 -0
  421. package/dist/story/definition.js +9 -0
  422. package/dist/story/diff.d.ts +9 -0
  423. package/dist/story/diff.js +97 -0
  424. package/dist/story/errors.d.ts +14 -0
  425. package/dist/story/errors.js +21 -0
  426. package/dist/story/gateways.d.ts +74 -0
  427. package/dist/story/gateways.js +3 -0
  428. package/dist/story/host.d.ts +27 -0
  429. package/dist/story/host.js +97 -0
  430. package/dist/story/index.d.ts +7 -0
  431. package/dist/story/index.js +9 -0
  432. package/dist/story/json.d.ts +16 -0
  433. package/dist/story/json.js +59 -0
  434. package/dist/story/live/artifact-gateway.d.ts +2 -0
  435. package/dist/story/live/artifact-gateway.js +82 -0
  436. package/dist/story/mode.d.ts +17 -0
  437. package/dist/story/mode.js +21 -0
  438. package/dist/story/orphans.d.ts +17 -0
  439. package/dist/story/orphans.js +15 -0
  440. package/dist/story/report.d.ts +30 -0
  441. package/dist/story/report.js +118 -0
  442. package/dist/story/run.d.ts +49 -0
  443. package/dist/story/run.js +160 -0
  444. package/dist/story/sequence.d.ts +30 -0
  445. package/dist/story/sequence.js +74 -0
  446. package/dist/story/settle.d.ts +94 -0
  447. package/dist/story/settle.js +70 -0
  448. package/dist/time/duration.d.ts +19 -0
  449. package/dist/time/duration.js +37 -0
  450. package/dist/time/index.d.ts +2 -0
  451. package/dist/time/index.js +4 -0
  452. package/dist/time/time.d.ts +15 -0
  453. package/dist/time/time.js +23 -0
  454. package/dist/vercel-cli/ansi.d.ts +13 -0
  455. package/dist/vercel-cli/ansi.js +32 -0
  456. package/dist/vercel-cli/arguments.d.ts +25 -0
  457. package/dist/vercel-cli/arguments.js +78 -0
  458. package/dist/vercel-cli/auth-config.d.ts +43 -0
  459. package/dist/vercel-cli/auth-config.js +36 -0
  460. package/dist/vercel-cli/clock.d.ts +9 -0
  461. package/dist/vercel-cli/clock.js +10 -0
  462. package/dist/vercel-cli/config-files.d.ts +24 -0
  463. package/dist/vercel-cli/config-files.js +40 -0
  464. package/dist/vercel-cli/context.d.ts +12 -0
  465. package/dist/vercel-cli/context.js +12 -0
  466. package/dist/vercel-cli/driver.d.ts +218 -0
  467. package/dist/vercel-cli/driver.js +364 -0
  468. package/dist/vercel-cli/entry.d.ts +8 -0
  469. package/dist/vercel-cli/entry.js +13 -0
  470. package/dist/vercel-cli/environment.d.ts +33 -0
  471. package/dist/vercel-cli/environment.js +72 -0
  472. package/dist/vercel-cli/errors.d.ts +8 -0
  473. package/dist/vercel-cli/errors.js +8 -0
  474. package/dist/vercel-cli/gateways.d.ts +103 -0
  475. package/dist/vercel-cli/gateways.js +4 -0
  476. package/dist/vercel-cli/index.d.ts +10 -0
  477. package/dist/vercel-cli/index.js +15 -0
  478. package/dist/vercel-cli/invocation.d.ts +234 -0
  479. package/dist/vercel-cli/invocation.js +397 -0
  480. package/dist/vercel-cli/keys.d.ts +14 -0
  481. package/dist/vercel-cli/keys.js +12 -0
  482. package/dist/vercel-cli/live/config-files.d.ts +28 -0
  483. package/dist/vercel-cli/live/config-files.js +66 -0
  484. package/dist/vercel-cli/live/process-gateway.d.ts +14 -0
  485. package/dist/vercel-cli/live/process-gateway.js +178 -0
  486. package/dist/vercel-cli/redaction.d.ts +13 -0
  487. package/dist/vercel-cli/redaction.js +22 -0
  488. package/dist/vercel-cli/report.d.ts +22 -0
  489. package/dist/vercel-cli/report.js +110 -0
  490. package/dist/vercel-cli/verbose.d.ts +7 -0
  491. package/dist/vercel-cli/verbose.js +24 -0
  492. package/dist/version.d.ts +20 -0
  493. package/dist/version.js +57 -0
  494. package/dist/vitest/config.d.ts +51 -0
  495. package/dist/vitest/config.js +61 -0
  496. package/dist/vitest/container-scope.d.ts +108 -0
  497. package/dist/vitest/container-scope.js +234 -0
  498. package/dist/vitest/diagnostics.d.ts +146 -0
  499. package/dist/vitest/diagnostics.js +306 -0
  500. package/dist/vitest/find-vitest.d.ts +7 -0
  501. package/dist/vitest/find-vitest.js +28 -0
  502. package/dist/vitest/fixtures.d.ts +64 -0
  503. package/dist/vitest/fixtures.js +172 -0
  504. package/dist/vitest/gateways.d.ts +78 -0
  505. package/dist/vitest/gateways.js +4 -0
  506. package/dist/vitest/index.d.ts +3 -0
  507. package/dist/vitest/index.js +9 -0
  508. package/dist/vitest/list-output.d.ts +3 -0
  509. package/dist/vitest/list-output.js +19 -0
  510. package/dist/vitest/live/list-gateway.d.ts +11 -0
  511. package/dist/vitest/live/list-gateway.js +107 -0
  512. package/dist/vitest/ownership.d.ts +29 -0
  513. package/dist/vitest/ownership.js +68 -0
  514. package/dist/vitest/plan.d.ts +66 -0
  515. package/dist/vitest/plan.js +104 -0
  516. package/dist/vitest/sandbox.d.ts +16 -0
  517. package/dist/vitest/sandbox.js +35 -0
  518. package/dist/vitest/test-events.d.ts +41 -0
  519. package/dist/vitest/test-events.js +92 -0
  520. package/dist/vitest/test-results.d.ts +84 -0
  521. package/dist/vitest/test-results.js +160 -0
  522. package/dist/vitest/types.d.ts +68 -0
  523. package/dist/vitest/types.js +4 -0
  524. package/package.json +119 -3
  525. package/skills/overview.md +33 -0
  526. package/skills/read-run-output.md +65 -0
  527. package/README.md +0 -3
@@ -0,0 +1,46 @@
1
+ import { splitTarget } from "../records/index.js";
2
+ import { BODY_EXCERPT_CHARS } from "../testserver/index.js";
3
+ /** Statuses whose answer has no body, so a `Response` can't be built with one. */
4
+ const NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);
5
+ /** The record of an API request to `target` that started at `startedAt` and ended with `outcome`. */
6
+ export function apiRequestRecord(request) {
7
+ return {
8
+ method: request.method,
9
+ url: request.target,
10
+ ...splitTarget(request.target),
11
+ authorization: request.authorization,
12
+ ...(request.requestBody === undefined ? {} : { requestBody: request.requestBody }),
13
+ ...(request.responseBody === undefined ? {} : { responseBody: request.responseBody }),
14
+ startedAt: request.startedAt,
15
+ durationMs: request.durationMs,
16
+ ...request.outcome,
17
+ };
18
+ }
19
+ /** Whether an answer with `status` to a `method` request carries no body. */
20
+ export function hasNullBody(method, status) {
21
+ return method === "HEAD" || NULL_BODY_STATUSES.has(status);
22
+ }
23
+ /**
24
+ * The failure an answer with `status` is, when `fetch` refuses it: a 410 or 502 (the Testserver sandbox has expired
25
+ * or can't be reached) is an `http-error`, a status no `Response` can carry is `malformed`. `undefined` for any other.
26
+ * The body is redacted whole before it is cut, so no secret is cut in half and left partly readable.
27
+ */
28
+ export function refusedAnswer(status, body, redact) {
29
+ if (status === 410 || status === 502) {
30
+ return { kind: "http-error", status, body: redact(new TextDecoder().decode(body)).slice(0, BODY_EXCERPT_CHARS) };
31
+ }
32
+ if (status < 200 || status > 599)
33
+ return { kind: "malformed", detail: `status ${status}` };
34
+ return undefined;
35
+ }
36
+ /** Whether `body` is one `container.fetch` can read whole at once: absent, or a `ContainerRequestBody`. */
37
+ export function readableWhole(body) {
38
+ return (body === undefined ||
39
+ body === null ||
40
+ typeof body === "string" ||
41
+ body instanceof ArrayBuffer ||
42
+ ArrayBuffer.isView(body) ||
43
+ body instanceof Blob ||
44
+ body instanceof FormData ||
45
+ body instanceof URLSearchParams);
46
+ }
@@ -0,0 +1,144 @@
1
+ import { type AnyFactoryDefinition, type FactoryCall, type FactoryGateway, type FactoryInput, type FactoryOptions, type FactoryOutput } from "../factories/index.ts";
2
+ import { type ApiRequestRecord } from "../records/index.ts";
3
+ import { type Clock, type TestserverServiceId } from "../testserver/index.ts";
4
+ import { type ContainerRequestInit } from "./api-request.ts";
5
+ import { type FeatureFlags } from "./feature-flags.ts";
6
+ import type { ContainerGateway, ContainerInfo, ContainerLogRecord } from "./gateways.ts";
7
+ /** The gateways and seams the SDK reaches Testserver through. Tests build it over fakes. */
8
+ export interface SdkContext {
9
+ readonly containers: ContainerGateway;
10
+ readonly factories: FactoryGateway;
11
+ readonly clock: Clock;
12
+ }
13
+ /** How long a data-plane call may take by default: the allowance vercel-internal gives infrastructure calls. */
14
+ export declare const DEFAULT_TIMEOUT_MS = 45000;
15
+ /**
16
+ * How long one container start attempt may take by default. Two attempts at 45s would outlast a 60s test timeout on
17
+ * a hung start.
18
+ */
19
+ export declare const DEFAULT_START_TIMEOUT_MS = 15000;
20
+ /** How many times a container start is attempted, as in vercel-internal's harness. */
21
+ export declare const START_ATTEMPTS = 2;
22
+ /** How long a container start waits before its next attempt. */
23
+ export declare const START_RETRY_DELAY_MS = 250;
24
+ /**
25
+ * The live Context: Testserver over `fetch`, each call under `timeoutMs` (default 45s) but each container start
26
+ * attempt under `startTimeoutMs` (default 15s), and the system clock.
27
+ */
28
+ export declare function liveSdkContext(options?: {
29
+ readonly timeoutMs?: number;
30
+ readonly startTimeoutMs?: number;
31
+ }): SdkContext;
32
+ /** Which container to start, and where. */
33
+ export interface ContainerOptions {
34
+ /**
35
+ * The Testserver URL of a Testserver sandbox the run holds, such as
36
+ * `readRunPayload().resources.testserverPool?.sandboxes[0]?.url`.
37
+ */
38
+ readonly testserverUrl: string;
39
+ /** The test id; by default a fresh one (`ts-` and 16 hex characters). At most 49 characters. */
40
+ readonly testId?: string;
41
+ /** A label Testserver shows for the container. */
42
+ readonly name?: string;
43
+ readonly meta?: Readonly<Record<string, unknown>>;
44
+ /**
45
+ * The feature flags the container's services read, by flag client, such as
46
+ * `{ all: { "env-var-config-secret-ui": true } }`; by default none. Set once the container has started and before
47
+ * it is returned, because each service reads them once, when it starts: no way to change them afterwards could
48
+ * know whether a service had already started.
49
+ */
50
+ readonly featureFlags?: FeatureFlags;
51
+ }
52
+ /** How one service answered a warmup: started, or why not, in `error`, redacted with the container's `redact`. */
53
+ export type ServiceWarmupOutcome = {
54
+ readonly serviceId: TestserverServiceId;
55
+ readonly ok: true;
56
+ readonly ms: number;
57
+ } | {
58
+ readonly serviceId: TestserverServiceId;
59
+ readonly ok: false;
60
+ readonly ms: number;
61
+ readonly error: string;
62
+ };
63
+ /** One `container.warmup` call: when it started on the SDK clock, how long it took, and how each service answered. */
64
+ export interface ServiceWarmup {
65
+ readonly startedAt: number;
66
+ readonly ms: number;
67
+ /** One per distinct service id, in the order first given. */
68
+ readonly services: readonly ServiceWarmupOutcome[];
69
+ }
70
+ /** A running container: the isolated state for one test, or one test file's tests, and the factories that seed it. */
71
+ export interface Container {
72
+ readonly testId: string;
73
+ readonly testserverUrl: string;
74
+ readonly info: ContainerInfo;
75
+ /** The feature flags it was started with, normalized: empty clients dropped, the rest in flag client order. */
76
+ readonly featureFlags: FeatureFlags;
77
+ /** Every factory call made so far, in order. */
78
+ readonly factoryCalls: readonly FactoryCall[];
79
+ /** Every API request `fetch` sent so far, failed ones included, in the order they ended. */
80
+ readonly apiRequests: readonly ApiRequestRecord[];
81
+ /** Every `warmup` with at least one service id, in the order they ended. */
82
+ readonly warmups: readonly ServiceWarmup[];
83
+ /** Seeds one entity through a factory definition (see `buildFactory`). */
84
+ build<D extends AnyFactoryDefinition>(definition: D, data: FactoryInput<D>, options?: FactoryOptions): Promise<FactoryOutput<D>>;
85
+ /** Seeds one entity through the factory at `path`, unchecked (see `buildUntypedFactory`). */
86
+ buildUntyped(path: string, data: unknown, options?: FactoryOptions): Promise<unknown>;
87
+ /**
88
+ * Sends one API request straight to the container's Testserver with its test id added, and nothing else: send
89
+ * `authorization` yourself. `path` starts with `/`; any other, a `test-id` header of the caller's, or a body that
90
+ * is a stream or an iterable, is a `TypeError`. Reads the whole answer, within the call timeout, and returns it
91
+ * whatever its status, but a 410 or 502 (the Testserver sandbox has expired or can't be reached) throws a
92
+ * `TestserverCallError`, its body excerpt redacted with `redact`, as does a timeout or a failed connection. An abort through `init.signal` rejects with the signal's reason. Each request is
93
+ * recorded in `apiRequests` before `fetch` resolves or rejects.
94
+ */
95
+ fetch(path: string, init?: ContainerRequestInit): Promise<Response>;
96
+ /**
97
+ * Starts the container's services `serviceIds` names, each by asking its `readyz` (`GET /_/service/<id>/readyz`),
98
+ * all at once, and resolves once each has answered, with how each did. Testserver starts a service on its first
99
+ * request otherwise, so warming the services a test will use moves their start ahead of it. A service that fails or
100
+ * doesn't answer within the call timeout is reported, not thrown: it starts on first use as before. Repeated ids
101
+ * are warmed once. An empty list sends nothing and records nothing; any other is recorded in `warmups` before it
102
+ * resolves. An id that is empty or holds `/`, `?`, `#`, `%`, `\` or whitespace, which Testserver couldn't route, is
103
+ * a `TypeError`, before anything is sent. Not an API request: it isn't recorded in `apiRequests`.
104
+ */
105
+ warmup(serviceIds: readonly TestserverServiceId[]): Promise<ServiceWarmup>;
106
+ /**
107
+ * Reads the container log: every record Testserver keeps for the container, finished or not, oldest first.
108
+ * Testserver keeps only the last 2,000, and none once the container has ended. A failed read throws a
109
+ * `TestserverCallError`.
110
+ */
111
+ log(): Promise<readonly ContainerLogRecord[]>;
112
+ /**
113
+ * `text` with every token secret the container has seen replaced by `<token>`: each string under a token field in
114
+ * its factory calls' inputs and responses, and each bearer token its API requests sent. For printing what
115
+ * Testserver logged.
116
+ */
117
+ redact(text: string): string;
118
+ /** Ends the container. Calling it again after it succeeded does nothing. */
119
+ end(): Promise<void>;
120
+ }
121
+ /**
122
+ * Starts a container and returns its handle; the caller ends it. Throws a `TestIdError` for a bad `testId` and a
123
+ * `TypeError` for `featureFlags` that aren't `FeatureFlags` before sending anything, and a `TestserverCallError` when
124
+ * the start fails.
125
+ *
126
+ * A start that may have reached Testserver and failed is followed by an attempt to end the container. When that end
127
+ * fails too, throws an `AggregateError` holding both call errors, the start's first and as its `cause`, and tries no
128
+ * more. Otherwise a start that timed out, couldn't connect, broke off, or got a 5xx other than 502 is tried once
129
+ * more after 250ms, under a fresh test id. The caller's `testId` is tried again only after a failed connection:
130
+ * ending a container retires its test id, and Testserver refuses every later request for a retired one. A start that
131
+ * fails every attempt throws the last attempt's `TestserverCallError`, carrying the attempts.
132
+ *
133
+ * Once a start succeeds, sets `featureFlags` before returning, one `PATCH /_/external/flags/<client>` for each
134
+ * client that has a flag, one after another, in `FEATURE_FLAG_CLIENTS` order, so they are in place before any
135
+ * service starts. A call that fails ends the container and throws its `TestserverCallError`, with no retry; when the
136
+ * end fails too, throws an `AggregateError` holding both, the feature flags' error first and as its `cause`.
137
+ */
138
+ export declare function startContainer(options: ContainerOptions, context?: SdkContext): Promise<Container>;
139
+ /**
140
+ * Starts a container (retrying a failed start as `startContainer` does), runs `body` with it, and ends it however
141
+ * `body` finishes. Returns what `body` returns, and rethrows what it throws. When `body` throws and ending fails too, throws an `AggregateError` holding both, the
142
+ * body's error first and as its `cause`.
143
+ */
144
+ export declare function withContainer<T>(options: ContainerOptions, body: (container: Container) => Promise<T>, context?: SdkContext): Promise<T>;
@@ -0,0 +1,346 @@
1
+ import { buildFactory, buildUntypedFactory, liveFactoryGateway, } from "../factories/index.js";
2
+ import { bearerToken, incomingHeaders, recordedBody, redactSecrets, tokenSecrets, } from "../records/index.js";
3
+ import { checkTestId, describeFailure, generateTestId, systemClock, TEST_ID_HEADER, TestserverCallError, testserverEndpoint, } from "../testserver/index.js";
4
+ import { apiRequestRecord, hasNullBody, readableWhole, refusedAnswer, } from "./api-request.js";
5
+ import { checkFeatureFlags, FEATURE_FLAG_CLIENTS, normalizeFeatureFlags } from "./feature-flags.js";
6
+ import { liveContainerGateway } from "./live/container-gateway.js";
7
+ /** How long a data-plane call may take by default: the allowance vercel-internal gives infrastructure calls. */
8
+ export const DEFAULT_TIMEOUT_MS = 45_000;
9
+ /**
10
+ * How long one container start attempt may take by default. Two attempts at 45s would outlast a 60s test timeout on
11
+ * a hung start.
12
+ */
13
+ export const DEFAULT_START_TIMEOUT_MS = 15_000;
14
+ /** How many times a container start is attempted, as in vercel-internal's harness. */
15
+ export const START_ATTEMPTS = 2;
16
+ /** How long a container start waits before its next attempt. */
17
+ export const START_RETRY_DELAY_MS = 250;
18
+ /**
19
+ * The live Context: Testserver over `fetch`, each call under `timeoutMs` (default 45s) but each container start
20
+ * attempt under `startTimeoutMs` (default 15s), and the system clock.
21
+ */
22
+ export function liveSdkContext(options = {}) {
23
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
24
+ const startTimeoutMs = options.startTimeoutMs ?? DEFAULT_START_TIMEOUT_MS;
25
+ return {
26
+ containers: liveContainerGateway({ timeoutMs, startTimeoutMs }),
27
+ factories: liveFactoryGateway({ timeoutMs }),
28
+ clock: systemClock,
29
+ };
30
+ }
31
+ /**
32
+ * Starts a container and returns its handle; the caller ends it. Throws a `TestIdError` for a bad `testId` and a
33
+ * `TypeError` for `featureFlags` that aren't `FeatureFlags` before sending anything, and a `TestserverCallError` when
34
+ * the start fails.
35
+ *
36
+ * A start that may have reached Testserver and failed is followed by an attempt to end the container. When that end
37
+ * fails too, throws an `AggregateError` holding both call errors, the start's first and as its `cause`, and tries no
38
+ * more. Otherwise a start that timed out, couldn't connect, broke off, or got a 5xx other than 502 is tried once
39
+ * more after 250ms, under a fresh test id. The caller's `testId` is tried again only after a failed connection:
40
+ * ending a container retires its test id, and Testserver refuses every later request for a retired one. A start that
41
+ * fails every attempt throws the last attempt's `TestserverCallError`, carrying the attempts.
42
+ *
43
+ * Once a start succeeds, sets `featureFlags` before returning, one `PATCH /_/external/flags/<client>` for each
44
+ * client that has a flag, one after another, in `FEATURE_FLAG_CLIENTS` order, so they are in place before any
45
+ * service starts. A call that fails ends the container and throws its `TestserverCallError`, with no retry; when the
46
+ * end fails too, throws an `AggregateError` holding both, the feature flags' error first and as its `cause`.
47
+ */
48
+ export async function startContainer(options, context = liveSdkContext()) {
49
+ if (options.testId !== undefined)
50
+ checkTestId(options.testId);
51
+ if (options.featureFlags !== undefined)
52
+ checkFeatureFlags(options.featureFlags);
53
+ const featureFlags = normalizeFeatureFlags(options.featureFlags ?? {});
54
+ const { testserverUrl } = options;
55
+ const firstStartedAt = context.clock.now();
56
+ let first;
57
+ for (let attempt = 1;; attempt += 1) {
58
+ const testId = options.testId ?? generateTestId();
59
+ const started = await context.containers.start({
60
+ testserverUrl,
61
+ testId,
62
+ ...(options.name === undefined ? {} : { name: options.name }),
63
+ ...(options.meta === undefined ? {} : { meta: options.meta }),
64
+ });
65
+ if (started.ok) {
66
+ await setFeatureFlags(context, { testserverUrl, testId }, featureFlags);
67
+ return new RunningContainer(context, testserverUrl, testId, started.info, featureFlags);
68
+ }
69
+ first ??= started.failure;
70
+ const startError = new TestserverCallError({
71
+ call: { method: "PUT", path: "/_/test" },
72
+ testId,
73
+ testserverUrl,
74
+ failure: started.failure,
75
+ ...(attempt === 1
76
+ ? {}
77
+ : { attempts: { count: attempt, elapsedMs: context.clock.now() - firstStartedAt, first } }),
78
+ });
79
+ // A start that never connected reached nothing, so there is nothing to end and its test id is not retired.
80
+ const reached = started.failure.kind !== "connect-failed";
81
+ if (reached) {
82
+ const ended = await context.containers.end({ testserverUrl, testId });
83
+ if (!ended.ok) {
84
+ const endError = new TestserverCallError({
85
+ call: { method: "DELETE", path: "/_/test" },
86
+ testId,
87
+ testserverUrl,
88
+ failure: ended.failure,
89
+ });
90
+ throw new AggregateError([startError, endError], `${startError.message}; ending container ${testId} after the failed start also failed: ${endError.message}`, { cause: startError });
91
+ }
92
+ }
93
+ const retired = reached && options.testId !== undefined;
94
+ if (attempt >= START_ATTEMPTS || retired || !retriesStart(started.failure))
95
+ throw startError;
96
+ await context.clock.sleep(START_RETRY_DELAY_MS);
97
+ }
98
+ }
99
+ /**
100
+ * Sets each client's feature flags in a container just started, one after another. A call that fails ends the
101
+ * container and throws, as `startContainer` documents.
102
+ */
103
+ async function setFeatureFlags(context, address, featureFlags) {
104
+ for (const client of FEATURE_FLAG_CLIENTS) {
105
+ const flags = featureFlags[client];
106
+ if (flags === undefined)
107
+ continue;
108
+ const set = await context.containers.setFeatureFlags({ ...address, client, flags });
109
+ if (set.ok)
110
+ continue;
111
+ const flagsError = new TestserverCallError({
112
+ call: { method: "PATCH", path: `/_/external/flags/${client}` },
113
+ ...address,
114
+ failure: set.failure,
115
+ });
116
+ const ended = await context.containers.end(address);
117
+ if (!ended.ok) {
118
+ const endError = new TestserverCallError({
119
+ call: { method: "DELETE", path: "/_/test" },
120
+ ...address,
121
+ failure: ended.failure,
122
+ });
123
+ throw new AggregateError([flagsError, endError], `${flagsError.message}; ending container ${address.testId} after its feature flags failed also failed: ${endError.message}`, { cause: flagsError });
124
+ }
125
+ throw flagsError;
126
+ }
127
+ }
128
+ /**
129
+ * Whether a failed start is worth another attempt: no answer, a failed or dropped connection, or a 5xx other than
130
+ * 502. A 4xx (a 410 included), a 502 (the Testserver sandbox has expired or can't be reached) or an answer that
131
+ * can't be read won't change.
132
+ */
133
+ function retriesStart(failure) {
134
+ switch (failure.kind) {
135
+ case "timeout":
136
+ case "connect-failed":
137
+ case "dropped":
138
+ return true;
139
+ case "http-error":
140
+ return failure.status >= 500 && failure.status !== 502;
141
+ case "malformed":
142
+ return false;
143
+ }
144
+ }
145
+ /**
146
+ * Starts a container (retrying a failed start as `startContainer` does), runs `body` with it, and ends it however
147
+ * `body` finishes. Returns what `body` returns, and rethrows what it throws. When `body` throws and ending fails too, throws an `AggregateError` holding both, the
148
+ * body's error first and as its `cause`.
149
+ */
150
+ export async function withContainer(options, body, context) {
151
+ const container = await startContainer(options, context);
152
+ let result;
153
+ try {
154
+ result = await body(container);
155
+ }
156
+ catch (error) {
157
+ try {
158
+ await container.end();
159
+ }
160
+ catch (endError) {
161
+ // oxlint-disable-next-line eslint/preserve-caught-error -- the body's error is the documented `cause`; `endError` is in `errors`.
162
+ throw new AggregateError([error, endError], `${messageOf(error)}; ending container ${container.testId} also failed: ${messageOf(endError)}`, { cause: error });
163
+ }
164
+ throw error;
165
+ }
166
+ await container.end();
167
+ return result;
168
+ }
169
+ class RunningContainer {
170
+ #context;
171
+ #factoryCalls = [];
172
+ #apiRequests = [];
173
+ #warmups = [];
174
+ /** Every token secret the container has seen, collected as each factory call and API request is recorded. */
175
+ #secrets = new Set();
176
+ #ended = false;
177
+ testserverUrl;
178
+ testId;
179
+ info;
180
+ featureFlags;
181
+ constructor(context, testserverUrl, testId, info, featureFlags) {
182
+ this.#context = context;
183
+ this.testserverUrl = testserverUrl;
184
+ this.testId = testId;
185
+ this.info = info;
186
+ this.featureFlags = featureFlags;
187
+ }
188
+ get factoryCalls() {
189
+ return [...this.#factoryCalls];
190
+ }
191
+ get apiRequests() {
192
+ return [...this.#apiRequests];
193
+ }
194
+ get warmups() {
195
+ return [...this.#warmups];
196
+ }
197
+ async build(definition, data, options) {
198
+ this.#assertRunning();
199
+ return buildFactory(this.#context, this.#target(), definition, data, options);
200
+ }
201
+ async buildUntyped(path, data, options) {
202
+ this.#assertRunning();
203
+ return buildUntypedFactory(this.#context, this.#target(), path, data, options);
204
+ }
205
+ async fetch(path, init) {
206
+ this.#assertRunning();
207
+ if (!path.startsWith("/")) {
208
+ throw new TypeError(`container.fetch takes a path under the Testserver URL, starting with "/", not ${JSON.stringify(path)}`);
209
+ }
210
+ if (new Headers(init?.headers).has(TEST_ID_HEADER)) {
211
+ throw new TypeError(`container.fetch adds the ${TEST_ID_HEADER} header itself; don't send one of your own`);
212
+ }
213
+ if (!readableWhole(init?.body)) {
214
+ throw new TypeError("container.fetch reads a body whole before sending it: pass a string, ArrayBuffer, typed array, Blob, FormData or URLSearchParams, not a stream or an iterable");
215
+ }
216
+ const { clock, containers } = this.#context;
217
+ const startedAt = clock.now();
218
+ // A `Request` reads every body type `ContainerRequestBody` holds, and fills in its content-type. Each is already in
219
+ // memory or a `Blob`, so reading it can't outlast an abort or the call timeout.
220
+ const request = new Request(testserverEndpoint(this.testserverUrl, path), init);
221
+ const body = new Uint8Array(await request.arrayBuffer());
222
+ const headers = [...request.headers];
223
+ const authorization = request.headers.get("authorization");
224
+ const bearer = bearerToken(authorization ?? undefined);
225
+ if (bearer !== undefined && bearer !== "")
226
+ this.#secrets.add(bearer);
227
+ const requestBody = recordedBody(body, body.byteLength, incomingHeaders(headers), bearer);
228
+ const signal = init?.signal ?? undefined;
229
+ const sent = await containers.sendApiRequest({
230
+ testserverUrl: this.testserverUrl,
231
+ testId: this.testId,
232
+ method: request.method,
233
+ path,
234
+ headers,
235
+ ...(body.byteLength === 0 ? {} : { body }),
236
+ ...(signal === undefined ? {} : { signal }),
237
+ });
238
+ const call = { method: request.method, path };
239
+ const record = (outcome, responseBody) => {
240
+ this.#apiRequests.push(apiRequestRecord({
241
+ method: request.method,
242
+ target: path,
243
+ authorization: authorization !== null,
244
+ requestBody,
245
+ responseBody,
246
+ startedAt,
247
+ durationMs: clock.now() - startedAt,
248
+ outcome,
249
+ }));
250
+ };
251
+ if (!sent.ok) {
252
+ if ("aborted" in sent) {
253
+ record({ error: "aborted" });
254
+ throw signal?.reason ?? new Error(`${call.method} ${path} was aborted`);
255
+ }
256
+ record({ error: describeFailure(sent.failure) });
257
+ throw this.#callError(call, sent.failure);
258
+ }
259
+ const { answer } = sent;
260
+ const responseBody = recordedBody(answer.body, answer.body.byteLength, incomingHeaders(answer.headers), bearer);
261
+ const refused = refusedAnswer(answer.status, answer.body, (text) => this.redact(text));
262
+ if (refused !== undefined) {
263
+ record({ status: answer.status, error: describeFailure(refused) }, responseBody);
264
+ throw this.#callError(call, refused);
265
+ }
266
+ record({ status: answer.status }, responseBody);
267
+ return new Response(hasNullBody(request.method, answer.status) ? null : new Uint8Array(answer.body), {
268
+ status: answer.status,
269
+ statusText: answer.statusText,
270
+ headers: answer.headers.map(([name, value]) => [name, value]),
271
+ });
272
+ }
273
+ async warmup(serviceIds) {
274
+ this.#assertRunning();
275
+ for (const serviceId of serviceIds)
276
+ checkServiceId(serviceId);
277
+ const { clock, containers } = this.#context;
278
+ const startedAt = clock.now();
279
+ const unique = [...new Set(serviceIds)];
280
+ if (unique.length === 0)
281
+ return { startedAt, ms: 0, services: [] };
282
+ const services = await Promise.all(unique.map(async (serviceId) => {
283
+ const from = clock.now();
284
+ const outcome = await containers.warmService({
285
+ testserverUrl: this.testserverUrl,
286
+ testId: this.testId,
287
+ serviceId,
288
+ });
289
+ const ms = clock.now() - from;
290
+ return outcome.ok
291
+ ? { serviceId, ok: true, ms }
292
+ : { serviceId, ok: false, ms, error: this.redact(describeFailure(outcome.failure)) };
293
+ }));
294
+ const warmup = { startedAt, ms: clock.now() - startedAt, services };
295
+ this.#warmups.push(warmup);
296
+ return warmup;
297
+ }
298
+ async log() {
299
+ this.#assertRunning();
300
+ const read = await this.#context.containers.readLog({ testserverUrl: this.testserverUrl, testId: this.testId });
301
+ if (!read.ok)
302
+ throw this.#callError({ method: "GET", path: "/_/log" }, read.failure);
303
+ return read.records;
304
+ }
305
+ redact(text) {
306
+ return redactSecrets(text, this.#secrets);
307
+ }
308
+ async end() {
309
+ if (this.#ended)
310
+ return;
311
+ const outcome = await this.#context.containers.end({ testserverUrl: this.testserverUrl, testId: this.testId });
312
+ if (!outcome.ok)
313
+ throw this.#callError({ method: "DELETE", path: "/_/test" }, outcome.failure);
314
+ this.#ended = true;
315
+ }
316
+ #target() {
317
+ return { testserverUrl: this.testserverUrl, testId: this.testId, record: (call) => this.#recordFactoryCall(call) };
318
+ }
319
+ /** Keeps a factory call's record, and every token secret in its input, options and response. */
320
+ #recordFactoryCall(call) {
321
+ this.#factoryCalls.push(call);
322
+ const seen = [call.input, call.options, call.outcome.ok ? call.outcome.response : undefined];
323
+ for (const value of seen)
324
+ for (const secret of tokenSecrets(value))
325
+ this.#secrets.add(secret);
326
+ }
327
+ #callError(call, failure) {
328
+ return new TestserverCallError({ call, testId: this.testId, testserverUrl: this.testserverUrl, failure });
329
+ }
330
+ #assertRunning() {
331
+ if (this.#ended)
332
+ throw new Error(`container ${this.testId} has ended`);
333
+ }
334
+ }
335
+ /** Characters that would change the path `/_/service/<id>/readyz` routes on: Testserver doesn't decode it. */
336
+ const UNROUTABLE_SERVICE_ID = /[/?#%\\\s]/;
337
+ /** Throws a `TypeError` for a service id Testserver couldn't route under `/_/service/<id>/`. */
338
+ function checkServiceId(serviceId) {
339
+ if (serviceId === "" || UNROUTABLE_SERVICE_ID.test(serviceId)) {
340
+ throw new TypeError(`container.warmup takes Testserver service ids, such as "api-user", that it can route under /_/service/<id>/; ` +
341
+ `not ${JSON.stringify(serviceId)}`);
342
+ }
343
+ }
344
+ function messageOf(error) {
345
+ return error instanceof Error ? error.message : String(error);
346
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The flag clients Testserver's flags datafile reads, in the order a container start sets them: `all`, the
3
+ * fallthrough every evaluation reaches, and the entity kinds `user`, `team` and `integration` (`FLAGS_CORE_CLIENTS`
4
+ * in vercel/api's `testserver/server/src/external/flags.ts`). A rule only tests whether an entity of its kind is in
5
+ * the evaluation context, so a value applies to every user, team or integration in the container.
6
+ */
7
+ export declare const FEATURE_FLAG_CLIENTS: readonly ["all", "user", "team", "integration"];
8
+ /** One flag client: `all`, `user`, `team` or `integration`. */
9
+ export type FeatureFlagClient = (typeof FEATURE_FLAG_CLIENTS)[number];
10
+ /** A feature flag's value: any JSON value, a number finite. */
11
+ export type FeatureFlagValue = string | number | boolean | null | readonly FeatureFlagValue[] | {
12
+ readonly [key: string]: FeatureFlagValue;
13
+ };
14
+ /**
15
+ * The feature flag values a container's services read, by flag client, each a map of flag names to JSON values,
16
+ * such as `{ all: { "env-var-config-secret-ui": true } }`.
17
+ */
18
+ export type FeatureFlags = {
19
+ readonly [C in FeatureFlagClient]?: Readonly<Record<string, FeatureFlagValue>>;
20
+ };
21
+ /**
22
+ * Throws a `TypeError` naming the problem unless `flags` is `FeatureFlags`: an object whose keys are flag clients,
23
+ * each holding an object of non-empty flag names to JSON values. A client that is `undefined` counts as absent.
24
+ * Testserver would take an unknown client and ignore it, so it is refused here.
25
+ */
26
+ export declare function checkFeatureFlags(flags: unknown): asserts flags is FeatureFlags;
27
+ /**
28
+ * `flags` with its empty clients dropped and the rest in `FEATURE_FLAG_CLIENTS` order, each a copy, so changing
29
+ * the object given afterwards changes nothing. Takes flags `checkFeatureFlags` accepted.
30
+ */
31
+ export declare function normalizeFeatureFlags(flags: FeatureFlags): FeatureFlags;
32
+ /**
33
+ * The canonical JSON of `flags`, normalized, with object keys sorted at every depth: two values that set the same
34
+ * flags give the same key, so `{}` and `{ all: {} }` do. Throws `checkFeatureFlags`' `TypeError` for flags that
35
+ * aren't `FeatureFlags`.
36
+ */
37
+ export declare function featureFlagsKey(flags: FeatureFlags): string;